From: Anders Carlsson Date: Sat, 6 Feb 2010 05:31:15 +0000 (+0000) Subject: Don't diagnose missing noreturns for uninstantiated templates. Fixes PR6247. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4855a52d2a4598883deafefea9029f454a4343ee;p=clang Don't diagnose missing noreturns for uninstantiated templates. Fixes PR6247. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95487 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 76ff8dc7cb..52a5162476 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2494,10 +2494,11 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body, bool ReturnsVoid = false; bool HasNoReturn = false; if (FunctionDecl *FD = dyn_cast(D)) { - // If the result type of the function is a dependent type, we don't know - // whether it will be void or not, so don't - if (FD->getResultType()->isDependentType()) + // For function templates, class templates and member function templates + // we'll do the analysis at instantiation time. + if (FD->isDependentContext()) return; + if (FD->getResultType()->isVoidType()) ReturnsVoid = true; if (FD->hasAttr() || diff --git a/test/SemaCXX/warn-missing-noreturn.cpp b/test/SemaCXX/warn-missing-noreturn.cpp new file mode 100644 index 0000000000..32d020f15f --- /dev/null +++ b/test/SemaCXX/warn-missing-noreturn.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn +void f() __attribute__((noreturn)); + +template void g(T) { // expected-warning {{function could be attribute 'noreturn'}} + f(); +} + +template void g(int); // expected-note {{in instantiation of function template specialization 'g' requested here}} + +template struct A { + void g() { // expected-warning {{function could be attribute 'noreturn'}} + f(); + } +}; + +template struct A; // expected-note {{in instantiation of member function 'A::g' requested here}} + +struct B { + template void g(T) { // expected-warning {{function could be attribute 'noreturn'}} + f(); + } +}; + +template void B::g(int); // expected-note {{in instantiation of function template specialization 'B::g' requested here}}