diff options
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 | ||||
-rw-r--r-- | test/CXX/except/except.spec/p1.cpp | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 4fea4002cb..c8628dbd49 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2286,7 +2286,21 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); ExprResult E = SemaRef.SubstExpr(OldNoexceptExpr, TemplateArgs); if (E.isUsable()) + E = SemaRef.CheckBooleanCondition(E.get(), E.get()->getLocStart()); + + if (E.isUsable()) { + SourceLocation ErrLoc; + llvm::APSInt NoexceptVal; NoexceptExpr = E.take(); + if (!NoexceptExpr->isTypeDependent() && + !NoexceptExpr->isValueDependent() && + !NoexceptExpr->isIntegerConstantExpr(NoexceptVal, SemaRef.Context, + &ErrLoc, /*evaluated=*/false)){ + SemaRef.Diag(ErrLoc, diag::err_noexcept_needs_constant_expression) + << NoexceptExpr->getSourceRange(); + NoexceptExpr = 0; + } + } } // Rebuild the function type diff --git a/test/CXX/except/except.spec/p1.cpp b/test/CXX/except/except.spec/p1.cpp index 86924bb49d..b45580a21c 100644 --- a/test/CXX/except/except.spec/p1.cpp +++ b/test/CXX/except/except.spec/p1.cpp @@ -60,14 +60,22 @@ namespace noex { } namespace noexcept_unevaluated { - template<typename T> void f(T) { + template<typename T> bool f(T) { T* x = 1; } template<typename T> - void g(T x) noexcept((f(x), sizeof(T) == 4)) { } + void g(T x) noexcept((sizeof(T) == sizeof(int)) || f(x)) { } void h() { g(1); } } + +namespace PR11084 { + template<int X> struct A { + static int f() noexcept(1/X) { return 10; } // expected-error{{argument to noexcept specifier must be a constant expression}} + }; + + void g() { A<0>::f(); } // expected-note{{in instantiation of template class 'PR11084::A<0>' requested here}} +} |