[OpenCL] Restrict pointer to member functions.
authorAnastasia Stulova <anastasia.stulova@arm.com>
Tue, 5 Jan 2021 13:02:09 +0000 (13:02 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Tue, 5 Jan 2021 13:32:18 +0000 (13:32 +0000)
Pointers to member functions are a special case
of function pointers and therefore have to be
disallowed.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D93958

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCLCXX/members.cl [new file with mode: 0644]

index 949df53..73a6aea 100644 (file)
@@ -6749,8 +6749,8 @@ static bool diagnoseOpenCLTypes(Scope *S, Sema &Se, Declarator &D,
 
   // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
   QualType NR = R;
-  while (NR->isPointerType()) {
-    if (NR->isFunctionPointerType()) {
+  while (NR->isPointerType() || NR->isMemberFunctionPointerType()) {
+    if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType()) {
       Se.Diag(D.getIdentifierLoc(), diag::err_opencl_function_pointer);
       D.setInvalidType();
       return false;
diff --git a/clang/test/SemaOpenCLCXX/members.cl b/clang/test/SemaOpenCLCXX/members.cl
new file mode 100644 (file)
index 0000000..699619c
--- /dev/null
@@ -0,0 +1,22 @@
+//RUN: %clang_cc1 %s -triple spir -cl-std=clc++ -verify -fsyntax-only
+
+// Check that pointer to member functions are diagnosed
+struct C {
+  void f(int n);
+};
+
+typedef void (C::*p_t)(int);
+
+template <class T> struct remove_reference { typedef T type; };
+template <class T> struct remove_reference<T &> { typedef T type; };
+
+template <typename T>
+void templ_test() {
+  typename remove_reference<T>::type *ptr; //expected-error{{pointers to functions are not allowed}}
+}
+
+void test() {
+  void (C::*p)(int);       //expected-error{{pointers to functions are not allowed}}
+  p_t p1;                  //expected-error{{pointers to functions are not allowed}}
+  templ_test<int (&)()>(); //expected-note{{in instantiation of function template specialization}}
+}