forked from OSchip/llvm-project
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
This commit is contained in:
parent
f5b160f89c
commit
e82f087378
|
@ -121,7 +121,7 @@ def warn_use_out_of_scope_declaration : Warning<
|
||||||
def err_inline_non_function : Error<
|
def err_inline_non_function : Error<
|
||||||
"'inline' can only appear on functions">;
|
"'inline' can only appear on functions">;
|
||||||
def warn_qual_return_type : Warning<
|
def warn_qual_return_type : Warning<
|
||||||
"type qualifier on return type has no effect">;
|
"'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">;
|
||||||
|
|
||||||
def warn_decl_shadow :
|
def warn_decl_shadow :
|
||||||
Warning<"declaration shadows a %select{"
|
Warning<"declaration shadows a %select{"
|
||||||
|
|
|
@ -1135,17 +1135,34 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
|
||||||
(!getLangOptions().CPlusPlus ||
|
(!getLangOptions().CPlusPlus ||
|
||||||
(!T->isDependentType() && !T->isRecordType()))) {
|
(!T->isDependentType() && !T->isRecordType()))) {
|
||||||
unsigned Quals = D.getDeclSpec().getTypeQualifiers();
|
unsigned Quals = D.getDeclSpec().getTypeQualifiers();
|
||||||
|
std::string QualStr;
|
||||||
|
unsigned NumQuals = 0;
|
||||||
SourceLocation Loc;
|
SourceLocation Loc;
|
||||||
if (Quals & Qualifiers::Const)
|
if (Quals & Qualifiers::Const) {
|
||||||
Loc = D.getDeclSpec().getConstSpecLoc();
|
Loc = D.getDeclSpec().getConstSpecLoc();
|
||||||
else if (Quals & Qualifiers::Volatile)
|
++NumQuals;
|
||||||
Loc = D.getDeclSpec().getVolatileSpecLoc();
|
QualStr = "const";
|
||||||
else {
|
|
||||||
assert((Quals & Qualifiers::Restrict) && "Unknown type qualifier");
|
|
||||||
Loc = D.getDeclSpec().getRestrictSpecLoc();
|
|
||||||
}
|
}
|
||||||
|
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);
|
SemaDiagnosticBuilder DB = Diag(Loc, diag::warn_qual_return_type);
|
||||||
|
DB << QualStr << NumQuals;
|
||||||
if (Quals & Qualifiers::Const)
|
if (Quals & Qualifiers::Const)
|
||||||
DB << FixItHint::CreateRemoval(D.getDeclSpec().getConstSpecLoc());
|
DB << FixItHint::CreateRemoval(D.getDeclSpec().getConstSpecLoc());
|
||||||
if (Quals & Qualifiers::Volatile)
|
if (Quals & Qualifiers::Volatile)
|
||||||
|
|
|
@ -292,10 +292,15 @@ namespace PR7598 {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const volatile Enum g2() { // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
void f() {
|
void f() {
|
||||||
const Enum v2 = v;
|
const Enum v2 = v;
|
||||||
Enum e = false ? g() : v;
|
Enum e = false ? g() : v;
|
||||||
Enum e2 = false ? v2 : v;
|
Enum e2 = false ? v2 : v;
|
||||||
|
Enum e3 = false ? g2() : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace test2 {
|
||||||
// PR5134
|
// PR5134
|
||||||
namespace test3 {
|
namespace test3 {
|
||||||
class Foo {
|
class Foo {
|
||||||
friend const int getInt(int inInt = 0); // expected-warning{{type qualifier on return type has no effect}}
|
friend const int getInt(int inInt = 0); // expected-warning{{'const' type qualifier on return type has no effect}}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue