From e82f0873780b72d49b294801d47e7f53bfca8645 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 13 Jul 2010 08:50:30 +0000 Subject: 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 --- clang/lib/Sema/SemaType.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'clang/lib') 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) -- cgit v1.2.3