Author: erichkeane Date: Thu Oct 12 16:01:53 2017 New Revision: 315638 URL: http://llvm.org/viewvc/llvm-project?rev=315638&view=rev Log: [Sema][Crash] Correctly handle an non-dependent noexcept expr in function template
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 Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/CXX/except/except.spec/p1.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=315638&r1=315637&r2=315638&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Oct 12 16:01:53 2017 @@ -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; Modified: cfe/trunk/test/CXX/except/except.spec/p1.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p1.cpp?rev=315638&r1=315637&r2=315638&view=diff ============================================================================== --- cfe/trunk/test/CXX/except/except.spec/p1.cpp (original) +++ cfe/trunk/test/CXX/except/except.spec/p1.cpp Thu Oct 12 16:01:53 2017 @@ -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>(); + } +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits