[PATCH] D38700: [Sema][Crash] Correctly handle an non-dependent noexcept expr in function template

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 12 16:02:17 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL315638: [Sema][Crash] Correctly handle an non-dependent noexcept expr in function… (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D38700?vs=118245&id=118858#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38700

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/except/except.spec/p1.cpp


Index: cfe/trunk/test/CXX/except/except.spec/p1.cpp
===================================================================
--- cfe/trunk/test/CXX/except/except.spec/p1.cpp
+++ cfe/trunk/test/CXX/except/except.spec/p1.cpp
@@ -86,3 +86,12 @@
     f<0>(); // expected-note{{in instantiation of function template specialization}}
   }
 }
+
+namespace FuncTmplNoexceptError {
+  int a = 0;
+  // expected-error at +1{{argument to noexcept specifier must be a constant expression}}
+  template <class T> T f() noexcept(a++){ return {};}
+  void g(){
+    f<int>();
+  }
+};
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -14865,10 +14865,16 @@
         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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38700.118858.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171012/16e99211/attachment.bin>


More information about the cfe-commits mailing list