]> granicus.if.org Git - clang/commitdiff
[Sema][Crash] Correctly handle an non-dependent noexcept expr in function template
authorErich Keane <erich.keane@intel.com>
Thu, 12 Oct 2017 23:01:53 +0000 (23:01 +0000)
committerErich Keane <erich.keane@intel.com>
Thu, 12 Oct 2017 23:01:53 +0000 (23:01 +0000)
It seems that all of the other templated cases are handled correctly,
however the function template case was not correctly handled. This
patch recovers from this condition by setting the function to noexcept
after diagnosing. Previously it simply set NoexceptExpr to null,
which caused an Assert when this was evaluated during substitution.

Differential Revision:https://reviews.llvm.org/D38700

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

lib/Sema/SemaDeclCXX.cpp
test/CXX/except/except.spec/p1.cpp

index c385e0481baabb43a6e36191b3aedbf98fe6e5c6..a01f9d5bab9afe1fae6dad6f2a840b50e67a0db9 100644 (file)
@@ -14865,10 +14865,16 @@ void Sema::checkExceptionSpecification(
         return;
       }
 
-      if (!NoexceptExpr->isValueDependent())
-        NoexceptExpr = VerifyIntegerConstantExpression(NoexceptExpr, nullptr,
-                         diag::err_noexcept_needs_constant_expression,
-                         /*AllowFold*/ false).get();
+      if (!NoexceptExpr->isValueDependent()) {
+        ExprResult Result = VerifyIntegerConstantExpression(
+            NoexceptExpr, nullptr, diag::err_noexcept_needs_constant_expression,
+            /*AllowFold*/ false);
+        if (Result.isInvalid()) {
+          ESI.Type = EST_BasicNoexcept;
+          return;
+        }
+        NoexceptExpr = Result.get();
+      }
       ESI.NoexceptExpr = NoexceptExpr;
     }
     return;
index fa53c9f5d23f44a05951927cea73515e71a6b7b0..03d75326a64322a9ba65fafd7923de456d440b3d 100644 (file)
@@ -86,3 +86,12 @@ namespace PR11084 {
     f<0>(); // expected-note{{in instantiation of function template specialization}}
   }
 }
+
+namespace FuncTmplNoexceptError {
+  int a = 0;
+  // expected-error@+1{{argument to noexcept specifier must be a constant expression}}
+  template <class T> T f() noexcept(a++){ return {};}
+  void g(){
+    f<int>();
+  }
+};