]> granicus.if.org Git - clang/commitdiff
Produce an error on encountering a pointer or reference to a qualified function type...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 12 Jul 2010 23:11:43 +0000 (23:11 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Mon, 12 Jul 2010 23:11:43 +0000 (23:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108209 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/function-type-qual.cpp

index 10121d86828aafccdc464431003e50b89d3a7e7a..8fda370e058c9d2db7b10a2c27318be1b8a90617 100644 (file)
@@ -2157,6 +2157,8 @@ def err_invalid_member_use_in_static_method : Error<
   "invalid use of member %0 in static member function">;
 def err_invalid_qualified_function_type : Error<
   "type qualifier is not allowed on this function">;
+def err_invalid_qualified_function_pointer : Error<
+  "type qualifier is not allowed on this function %select{pointer|reference}0">;
 def err_invalid_qualified_typedef_function_type_use : Error<
   "a qualified function type cannot be used to declare a "
   "%select{static member|nonmember}0 function">;
index 73de52476fba2ebdb14bb93161cf230c65f24478..318ae494f137cb75a50e218725f4d694ca408256 100644 (file)
@@ -2861,6 +2861,23 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD,
     return NewVD->setInvalidDecl();
   }
 
+  // Function pointers and references cannot have qualified function type, only
+  // function pointer-to-members can do that.
+  QualType Pointee;
+  unsigned PtrOrRef = 0;
+  if (const PointerType *Ptr = T->getAs<PointerType>())
+    Pointee = Ptr->getPointeeType();
+  else if (const ReferenceType *Ref = T->getAs<ReferenceType>()) {
+    Pointee = Ref->getPointeeType();
+    PtrOrRef = 1;
+  }
+  if (!Pointee.isNull() && Pointee->isFunctionProtoType() &&
+      Pointee->getAs<FunctionProtoType>()->getTypeQuals() != 0) {
+    Diag(NewVD->getLocation(), diag::err_invalid_qualified_function_pointer)
+        << PtrOrRef;
+    return NewVD->setInvalidDecl();
+  }
+
   if (!Previous.empty()) {
     Redeclaration = true;
     MergeVarDecl(NewVD, Previous);
index ec27748900710a22dfd4f2729fba0989aba1bddb..8ebb50607025610a4794cbbedb1ea090a6996e90 100644 (file)
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 void f() const; // expected-error {{type qualifier is not allowed on this function}}
+void (*pf)() const; // expected-error {{type qualifier is not allowed on this function pointer}}
+void (&rf)() const = f; // expected-error {{type qualifier is not allowed on this function reference}}
 
 typedef void cfn() const; 
 cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function}}
@@ -21,3 +23,6 @@ class C {
 
   int x;
 };
+
+void (C::*mpf)() const;
+cfn C::*mpg;