From: Douglas Gregor Date: Thu, 27 Jan 2011 01:30:16 +0000 (+0000) Subject: Cope with parenthesized function declarators when emitting a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=944aa60777e6ea1015c9423107f7925f6d91f4a0;p=clang Cope with parenthesized function declarators when emitting a 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 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 64d5c428f3..9e1d067fda 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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); diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp index a2533ca2cb..c81c844f34 100644 --- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp @@ -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}}