]> granicus.if.org Git - clang/commitdiff
Ignore noreturn when checking function template specializations
authorReid Kleckner <reid@kleckner.net>
Tue, 10 Sep 2013 22:21:37 +0000 (22:21 +0000)
committerReid Kleckner <reid@kleckner.net>
Tue, 10 Sep 2013 22:21:37 +0000 (22:21 +0000)
As requested when applying the same logic to calling conventions.

Reviewers: rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D1634

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190441 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaTemplate/function-template-specialization-noreturn.cpp [new file with mode: 0644]

index b6313307c421e4b9d43aa532ddfc3decbd1c9058..d3223356baadae70338841cbd380e2208eeed12e 100644 (file)
@@ -6415,12 +6415,15 @@ bool Sema::CheckFunctionTemplateSpecialization(
         }
       }
 
-      // Ignore differences in calling convention until decl merging.
+      // Ignore differences in calling convention and noreturn until decl
+      // merging.
       const FunctionProtoType *TmplFT =
           TmplFD->getType()->castAs<FunctionProtoType>();
-      if (FPT->getCallConv() != TmplFT->getCallConv()) {
+      if (FPT->getCallConv() != TmplFT->getCallConv() ||
+          FPT->getNoReturnAttr() != TmplFT->getNoReturnAttr()) {
         FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
         EPI.ExtInfo = EPI.ExtInfo.withCallingConv(TmplFT->getCallConv());
+        EPI.ExtInfo = EPI.ExtInfo.withNoReturn(TmplFT->getNoReturnAttr());
         FT = Context.getFunctionType(FPT->getResultType(), FPT->getArgTypes(),
                                      EPI);
       }
diff --git a/test/SemaTemplate/function-template-specialization-noreturn.cpp b/test/SemaTemplate/function-template-specialization-noreturn.cpp
new file mode 100644 (file)
index 0000000..3e1f618
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Split from function-template-specialization.cpp because the noreturn warning
+// requires analysis-based warnings, which the other errors in that test case
+// disable.
+
+template <int N> void __attribute__((noreturn)) f3() { __builtin_unreachable(); }
+template <> void f3<1>() { } // expected-warning {{function declared 'noreturn' should not return}}