r364423 - [OpenCL] Improve diagnostic for placement new
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 26 06:31:24 PDT 2019
Author: svenvh
Date: Wed Jun 26 06:31:24 2019
New Revision: 364423
URL: http://llvm.org/viewvc/llvm-project?rev=364423&view=rev
Log:
[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
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=364423&r1=364422&r2=364423&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 26 06:31:24 2019
@@ -8809,6 +8809,9 @@ def ext_opencl_ext_vector_type_rgba_sele
"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">,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=364423&r1=364422&r2=364423&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jun 26 06:31:24 2019
@@ -2413,7 +2413,11 @@ bool Sema::FindAllocationFunctions(Sourc
}
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;
}
Modified: cfe/trunk/test/SemaOpenCLCXX/newdelete.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/newdelete.cl?rev=364423&r1=364422&r2=364423&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCLCXX/newdelete.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/newdelete.cl Wed Jun 26 06:31:24 2019
@@ -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 at +1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
More information about the cfe-commits
mailing list