Cope with parenthesized function declarators when emitting a

diagnostic about ref-qualifiers where they do not belong.

llvm-svn: 124344
This commit is contained in:
Douglas Gregor 2011-01-27 01:30:16 +00:00
parent 9864b5ec5f
commit dff0be70ba
2 changed files with 12 additions and 2 deletions

View File

@ -1901,8 +1901,16 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
if (FnTy->getRefQualifier()) { if (FnTy->getRefQualifier()) {
if (D.isFunctionDeclarator()) { if (D.isFunctionDeclarator()) {
SourceLocation Loc SourceLocation Loc = D.getIdentifierLoc();
= D.getTypeObject(D.getNumTypeObjects()-1).Fun.getRefQualifierLoc(); 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) Diag(Loc, diag::err_invalid_ref_qualifier_function_type)
<< (FnTy->getRefQualifier() == RQ_LValue) << (FnTy->getRefQualifier() == RQ_LValue)
<< FixItHint::CreateRemoval(Loc); << FixItHint::CreateRemoval(Loc);

View File

@ -24,3 +24,5 @@ struct Y {
void (X::*mpf1)() & = &X::f0; void (X::*mpf1)() & = &X::f0;
void (X::*mpf2)() && = &X::f1; 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}}