diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-07-13 08:50:30 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-07-13 08:50:30 +0000 |
| commit | e82f0873780b72d49b294801d47e7f53bfca8645 (patch) | |
| tree | 96a872f6ddcd54d63d4dfe3b66882506eb126bf1 /clang/lib | |
| parent | f5b160f89c0ac539667d4e739ff699949ad465fa (diff) | |
| download | bcm5719-llvm-e82f0873780b72d49b294801d47e7f53bfca8645.tar.gz bcm5719-llvm-e82f0873780b72d49b294801d47e7f53bfca8645.zip | |
Improve diagnostics for the "type qualifier on return type has no
effect warning" by printing the qualifiers we saw and correctly
pluralizing the message, e.g.,
test/SemaCXX/conditional-expr.cpp:295:3: warning: 'const volatile' type
qualifiers on return type have no effect
const volatile Enum g2() {
^~~~~ ~~~~~~~~
llvm-svn: 108236
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index dc3cea1a3c5..a4fc98cd958 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1135,17 +1135,34 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S, (!getLangOptions().CPlusPlus || (!T->isDependentType() && !T->isRecordType()))) { unsigned Quals = D.getDeclSpec().getTypeQualifiers(); + std::string QualStr; + unsigned NumQuals = 0; SourceLocation Loc; - if (Quals & Qualifiers::Const) + if (Quals & Qualifiers::Const) { Loc = D.getDeclSpec().getConstSpecLoc(); - else if (Quals & Qualifiers::Volatile) - Loc = D.getDeclSpec().getVolatileSpecLoc(); - else { - assert((Quals & Qualifiers::Restrict) && "Unknown type qualifier"); - Loc = D.getDeclSpec().getRestrictSpecLoc(); + ++NumQuals; + QualStr = "const"; + } + if (Quals & Qualifiers::Volatile) { + if (NumQuals == 0) { + Loc = D.getDeclSpec().getVolatileSpecLoc(); + QualStr = "volatile"; + } else + QualStr += " volatile"; + ++NumQuals; } - + if (Quals & Qualifiers::Restrict) { + if (NumQuals == 0) { + Loc = D.getDeclSpec().getRestrictSpecLoc(); + QualStr = "restrict"; + } else + QualStr += " restrict"; + ++NumQuals; + } + assert(NumQuals > 0 && "No known qualifiers?"); + SemaDiagnosticBuilder DB = Diag(Loc, diag::warn_qual_return_type); + DB << QualStr << NumQuals; if (Quals & Qualifiers::Const) DB << FixItHint::CreateRemoval(D.getDeclSpec().getConstSpecLoc()); if (Quals & Qualifiers::Volatile) |

