]> granicus.if.org Git - clang/commitdiff
Cope with parenthesized function declarators when emitting a
authorDouglas Gregor <dgregor@apple.com>
Thu, 27 Jan 2011 01:30:16 +0000 (01:30 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 27 Jan 2011 01:30:16 +0000 (01:30 +0000)
diagnostic about ref-qualifiers where they do not belong.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124344 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp

index 64d5c428f3d308a0dc2365b23eee28590425e3be..9e1d067fda87a6a6bb43477baca588cb1d329c1b 100644 (file)
@@ -1901,8 +1901,16 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
           
       if (FnTy->getRefQualifier()) {
         if (D.isFunctionDeclarator()) {
-          SourceLocation Loc
-            = D.getTypeObject(D.getNumTypeObjects()-1).Fun.getRefQualifierLoc();
+          SourceLocation Loc = D.getIdentifierLoc();
+          for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
+            const DeclaratorChunk &Chunk = D.getTypeObject(N-I-1);
+            if (Chunk.Kind == DeclaratorChunk::Function &&
+                Chunk.Fun.hasRefQualifier()) {
+              Loc = Chunk.Fun.getRefQualifierLoc();
+              break;
+            }
+          }
+
           Diag(Loc, diag::err_invalid_ref_qualifier_function_type)
             << (FnTy->getRefQualifier() == RQ_LValue)
             << FixItHint::CreateRemoval(Loc);
index a2533ca2cbae69e08fb299f547176bef0ed56169..c81c844f3448eddb623316e6ac9be95163678781 100644 (file)
@@ -24,3 +24,5 @@ struct Y {
 void (X::*mpf1)() & = &X::f0;
 void (X::*mpf2)() && = &X::f1;
 
+
+void (f() &&); // expected-error{{ref-qualifier '&&' is only allowed on non-static member functions, member function pointers, and typedefs of function types}}