]> granicus.if.org Git - clang/commitdiff
Don't diagnose missing noreturns for uninstantiated templates. Fixes PR6247.
authorAnders Carlsson <andersca@mac.com>
Sat, 6 Feb 2010 05:31:15 +0000 (05:31 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 6 Feb 2010 05:31:15 +0000 (05:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95487 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaCXX/warn-missing-noreturn.cpp [new file with mode: 0644]

index 76ff8dc7cb92fe280b754d21513ce80953636508..52a5162476532ac06304cd8e09a3f718c0a6477c 100644 (file)
@@ -2494,10 +2494,11 @@ void Sema::CheckFallThroughForFunctionDef(Decl *D, Stmt *Body,
   bool ReturnsVoid = false;
   bool HasNoReturn = false;
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(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<NoReturnAttr>() ||
diff --git a/test/SemaCXX/warn-missing-noreturn.cpp b/test/SemaCXX/warn-missing-noreturn.cpp
new file mode 100644 (file)
index 0000000..32d020f
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn
+void f() __attribute__((noreturn));
+
+template<typename T> void g(T) { // expected-warning {{function could be 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'}}
+    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'}}
+    f();
+  }
+};
+
+template void B::g<int>(int); // expected-note {{in instantiation of function template specialization 'B::g<int>' requested here}}