[OpenCL] Improve diagnostic for placement new
authorSven van Haastregt <sven.vanhaastregt@arm.com>
Wed, 26 Jun 2019 13:31:24 +0000 (13:31 +0000)
committerSven van Haastregt <sven.vanhaastregt@arm.com>
Wed, 26 Jun 2019 13:31:24 +0000 (13:31 +0000)
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

llvm-svn: 364423

clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaOpenCLCXX/newdelete.cl

index 2abf7d73c1e52ba99aa4391d1751a33bb38c58fa..b9d081c7e2a7bbbb149b0f0eabffc4f7c28c7b30 100644 (file)
@@ -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<OpenCLUnsupportedRGBA>;
 
+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">,
index b59f3faa6e6618e2813ba65991d2e5a33391124a..32b35ba7c32b0ca9c76767195baed169c7d9f8e7 100644 (file)
@@ -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;
     }
 
index ce6273f3be77eaa856c4b983bdc0e7289c46cd5c..14be4550c0fc639e6494fee8b51075687c84afe5 100644 (file)
@@ -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}}