[cfe-commits] r108209 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/function-type-qual.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jul 12 16:11:43 PDT 2010


Author: cornedbee
Date: Mon Jul 12 18:11:43 2010
New Revision: 108209

URL: http://llvm.org/viewvc/llvm-project?rev=108209&view=rev
Log:
Produce an error on encountering a pointer or reference to a qualified function type. Fixes PR7470.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=108209&r1=108208&r2=108209&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jul 12 18:11:43 2010
@@ -2157,6 +2157,8 @@
   "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">;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=108209&r1=108208&r2=108209&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 12 18:11:43 2010
@@ -2861,6 +2861,23 @@
     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);

Modified: cfe/trunk/test/SemaCXX/function-type-qual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-type-qual.cpp?rev=108209&r1=108208&r2=108209&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-type-qual.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-type-qual.cpp Mon Jul 12 18:11:43 2010
@@ -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 @@
 
   int x;
 };
+
+void (C::*mpf)() const;
+cfn C::*mpg;





More information about the cfe-commits mailing list