aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaType.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-07-13 08:50:30 +0000
committerDouglas Gregor <dgregor@apple.com>2010-07-13 08:50:30 +0000
commitde80ec1fa947855d2e53722a8cd71367ff513481 (patch)
tree22ceaf6afd0878c875e743c4e8e82fd6a12d29dc /lib/Sema/SemaType.cpp
parent218f47ff746b2216e949e79a287c034fd0bd8713 (diff)
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() { ^~~~~ ~~~~~~~~ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108236 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r--lib/Sema/SemaType.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index dc3cea1a3c..a4fc98cd95 100644
--- a/lib/Sema/SemaType.cpp
+++ b/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)