From: Sven van Haastregt Date: Wed, 26 Jun 2019 13:31:24 +0000 (+0000) Subject: [OpenCL] Improve diagnostic for placement new X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f269c05476a4fcb055be233e013966ad0b25391f;p=clang [OpenCL] Improve diagnostic for placement new Without an explicit declaration for placement new, clang would reject uses of placement new with "'default new' is not supported in OpenCL C++". This may mislead users into thinking that placement new is not supported, see e.g. PR42060. Clarify that placement new requires an explicit declaration. Differential Revision: https://reviews.llvm.org/D63561 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364423 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2abf7d73c1..b9d081c7e2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -8809,6 +8809,9 @@ def ext_opencl_ext_vector_type_rgba_selector: ExtWarn< "vector component name '%0' is an OpenCL version 2.2 feature">, InGroup; +def err_openclcxx_placement_new : Error< + "use of placement new requires explicit declaration">; + // MIG routine annotations. def warn_mig_server_routine_does_not_return_kern_return_t : Warning< "'mig_server_routine' attribute only applies to routines that return a kern_return_t">, diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index b59f3faa6e..32b35ba7c3 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2413,7 +2413,11 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, } if (getLangOpts().OpenCLCPlusPlus && R.empty()) { - Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new"; + if (PlaceArgs.empty()) { + Diag(StartLoc, diag::err_openclcxx_not_supported) << "default new"; + } else { + Diag(StartLoc, diag::err_openclcxx_placement_new); + } return true; } diff --git a/test/SemaOpenCLCXX/newdelete.cl b/test/SemaOpenCLCXX/newdelete.cl index ce6273f3be..14be4550c0 100644 --- a/test/SemaOpenCLCXX/newdelete.cl +++ b/test/SemaOpenCLCXX/newdelete.cl @@ -21,7 +21,7 @@ class B { void test_default_new_delete(void *buffer, A **pa) { A *a = new A; // expected-error {{'default new' is not supported in OpenCL C++}} delete a; // expected-error {{'default delete' is not supported in OpenCL C++}} - *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}} + *pa = new (buffer) A; // expected-error {{use of placement new requires explicit declaration}} } // expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}