[cfe-commits] r95487 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/warn-missing-noreturn.cpp

Anders Carlsson andersca at mac.com
Fri Feb 5 21:31:21 PST 2010


Author: andersca
Date: Fri Feb  5 23:31:15 2010
New Revision: 95487

URL: http://llvm.org/viewvc/llvm-project?rev=95487&view=rev
Log:
Don't diagnose missing noreturns for uninstantiated templates. Fixes PR6247.

Added:
    cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=95487&r1=95486&r2=95487&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb  5 23:31:15 2010
@@ -2494,10 +2494,11 @@
   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>() ||

Added: cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp?rev=95487&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp Fri Feb  5 23:31:15 2010
@@ -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}}





More information about the cfe-commits mailing list