of the function in question when applicable (that is, not for blocks).
Patch by Joerg Sonnenberger with some stylistic tweaks by me.
When discussing this weth Joerg, streaming the decl directly into the
diagnostic didn't work because we have a pointer-to-const, and the
overload doesn't accept such. In order to make my style tweaks to the
patch, I first changed the overload to accept a pointer-to-const, and
then changed the diagnostic printing layer to also use
a pointer-to-const, cleaning up a gross line of code along the way.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138854
91177308-0d34-0410-b5e6-
96231b3b80d8
/// Insertion operator for diagnostics. This allows sending NamedDecl's
/// into a diagnostic with <<.
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
- NamedDecl* ND) {
+ const NamedDecl* ND) {
DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), Diagnostic::ak_nameddecl);
return DB;
}
def err_falloff_nonvoid_block : Error<
"control reaches end of non-void block">;
def warn_suggest_noreturn_function : Warning<
- "function could be attribute 'noreturn'">,
+ "function %0 could be declared with attribute 'noreturn'">,
InGroup<DiagGroup<"missing-noreturn">>, DefaultIgnore;
def warn_suggest_noreturn_block : Warning<
- "block could be attribute 'noreturn'">,
+ "block could be declared with attribute 'noreturn'">,
InGroup<DiagGroup<"missing-noreturn">>, DefaultIgnore;
def warn_unreachable : Warning<"will never be executed">,
InGroup<DiagGroup<"unreachable-code">>, DefaultIgnore;
"Invalid modifier for NamedDecl* argument");
Qualified = false;
}
- reinterpret_cast<NamedDecl*>(Val)->
- getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
+ const NamedDecl *ND = reinterpret_cast<const NamedDecl*>(Val);
+ ND->getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
break;
}
case Diagnostic::ak_nestednamespec: {
CD.diag_AlwaysFallThrough_ReturnsNonVoid);
break;
case NeverFallThroughOrReturn:
- if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn)
- S.Diag(Compound->getLBracLoc(),
- CD.diag_NeverFallThroughOrReturn);
+ if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn)
+ << FD;
+ } else {
+ S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn);
+ }
+ }
break;
case NeverFallThrough:
break;
// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code
int j;
-void test1() { // expected-warning {{function could be attribute 'noreturn'}}
- ^ (void) { while (1) { } }(); // expected-warning {{block could be attribute 'noreturn'}}
+void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}}
+ ^ (void) { while (1) { } }(); // expected-warning {{block could be declared with attribute 'noreturn'}}
^ (void) { if (j) while (1) { } }();
while (1) { }
}
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type
void f() __attribute__((noreturn));
-template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}}
+template<typename T> void g(T) { // expected-warning {{function 'g<int>' could be declared with attribute 'noreturn'}}
f();
}
template void g<int>(int); // expected-note {{in instantiation of function template specialization 'g<int>' requested here}}
template<typename T> struct A {
- void g() { // expected-warning {{function could be attribute 'noreturn'}}
+ void g() { // expected-warning {{function 'g' could be declared with attribute 'noreturn'}}
f();
}
};
template struct A<int>; // expected-note {{in instantiation of member function 'A<int>::g' requested here}}
struct B {
- template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}}
+ template<typename T> void g(T) { // expected-warning {{function 'g<int>' could be declared with attribute 'noreturn'}}
f();
}
};
void *f;
A() : f(0) { }
- A(int) : f(h()) { } // expected-warning {{function could be attribute 'noreturn'}}
+ A(int) : f(h()) { } // expected-warning {{function 'A' could be declared with attribute 'noreturn'}}
A(char) : f(j()) { }
A(bool b) : f(b ? h() : j()) { }
};
}
// PR5286
-void test3(int a) { // expected-warning {{function could be attribute 'noreturn'}}
+void test3(int a) { // expected-warning {{function 'test3' could be declared with attribute 'noreturn'}}
while (1) {
if (a)
@throw (id)0;