diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-10-19 06:04:55 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-10-19 06:04:55 +0000 |
commit | 43f5103f8051bbac19022e6edaf7d9138b0f3c0f (patch) | |
tree | 2f0507637db90dcf86b4bf714f5aa6f49799784d /lib/Sema/SemaType.cpp | |
parent | 13102ffbb00f1397fa02950e0cbc82d17be21792 (diff) |
Improve the warning for cv-qualifiers on free functions, from Ahmed Charles!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142478 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r-- | lib/Sema/SemaType.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index f3a705f93e..f828b144d6 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -555,6 +555,8 @@ static void maybeSynthesizeBlockSignature(TypeProcessingState &state, /*args*/ 0, 0, /*type quals*/ 0, /*ref-qualifier*/true, SourceLocation(), + /*const qualifier*/SourceLocation(), + /*volatile qualifier*/SourceLocation(), /*mutable qualifier*/SourceLocation(), /*EH*/ EST_None, SourceLocation(), 0, 0, 0, 0, /*parens*/ loc, loc, @@ -2431,10 +2433,37 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, << Quals; } else { if (FnTy->getTypeQuals() != 0) { - if (D.isFunctionDeclarator()) - S.Diag(D.getIdentifierLoc(), - diag::err_invalid_qualified_function_type); - else + if (D.isFunctionDeclarator()) { + SourceRange Range = 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.TypeQuals != 0) { + switch (Chunk.Fun.TypeQuals) { + case Qualifiers::Const: + Range = Chunk.Fun.getConstQualifierLoc(); + break; + case Qualifiers::Volatile: + Range = Chunk.Fun.getVolatileQualifierLoc(); + break; + case Qualifiers::Const | Qualifiers::Volatile: { + SourceLocation CLoc = Chunk.Fun.getConstQualifierLoc(); + SourceLocation VLoc = Chunk.Fun.getVolatileQualifierLoc(); + if (S.getSourceManager() + .isBeforeInTranslationUnit(CLoc, VLoc)) { + Range = SourceRange(CLoc, VLoc); + } else { + Range = SourceRange(VLoc, CLoc); + } + } + break; + } + break; + } + } + S.Diag(Range.getBegin(), diag::err_invalid_qualified_function_type) + << FixItHint::CreateRemoval(Range); + } else S.Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_typedef_function_type_use) << FreeFunction; |