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

Sebastian Redl sebastian.redl at getdesigned.at
Fri Jul 9 14:26:08 PDT 2010


Author: cornedbee
Date: Fri Jul  9 16:26:08 2010
New Revision: 108018

URL: http://llvm.org/viewvc/llvm-project?rev=108018&view=rev
Log:
Slightly improve the diagnostic when using a qualified function typedef to declare nonmember or static member functions.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaType.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=108018&r1=108017&r2=108018&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul  9 16:26:08 2010
@@ -2158,8 +2158,8 @@
 def err_invalid_qualified_function_type : Error<
   "type qualifier is not allowed on this function">;
 def err_invalid_qualified_typedef_function_type_use : Error<
-  "a qualified function type cannot be used to declare a nonmember function "
-  "or a static member function">;
+  "a qualified function type cannot be used to declare a "
+  "%select{static member|nonmember}0 function">;
 
 def err_invalid_non_static_member_use : Error<
   "invalid use of nonstatic data member %0">;

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=108018&r1=108017&r2=108018&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Jul  9 16:26:08 2010
@@ -1320,18 +1320,19 @@
     // for a nonstatic member function, the function type to which a pointer
     // to member refers, or the top-level function type of a function typedef
     // declaration.
+    bool FreeFunction = (D.getContext() != Declarator::MemberContext &&
+        (!D.getCXXScopeSpec().isSet() ||
+         !computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)->isRecord()));
     if (FnTy->getTypeQuals() != 0 &&
         D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
-        ((D.getContext() != Declarator::MemberContext &&
-          (!D.getCXXScopeSpec().isSet() ||
-           !computeDeclContext(D.getCXXScopeSpec(), /*FIXME:*/true)
-              ->isRecord())) ||
+        (FreeFunction ||
          D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
       if (D.isFunctionDeclarator())
         Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
       else
         Diag(D.getIdentifierLoc(),
-             diag::err_invalid_qualified_typedef_function_type_use);
+             diag::err_invalid_qualified_typedef_function_type_use)
+          << FreeFunction;
 
       // Strip the cv-quals from the type.
       T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),

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=108018&r1=108017&r2=108018&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-type-qual.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-type-qual.cpp Fri Jul  9 16:26:08 2010
@@ -3,13 +3,13 @@
 void f() const; // expected-error {{type qualifier is not allowed on this function}}
 
 typedef void cfn() const; 
-cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}}
+cfn f2; // expected-error {{a qualified function type cannot be used to declare a nonmember function}}
 
 class C {
   void f() const;
   cfn f2;
   static void f3() const; // expected-error {{type qualifier is not allowed on this function}}
-  static cfn f4; // expected-error {{a qualified function type cannot be used to declare a nonmember function or a static member function}}
+  static cfn f4; // expected-error {{a qualified function type cannot be used to declare a static member function}}
 
   void m1() {
     x = 0;





More information about the cfe-commits mailing list