Skip to content
Snippets Groups Projects
Commit 5c340e80 authored by Douglas Gregor's avatar Douglas Gregor
Browse files

After instantiating a 'noexcept' expression, be sure to convert it to

a boolean value and check that it is a constant expression. Fixes
PR11084.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141511 91177308-0d34-0410-b5e6-96231b3b80d8
parent 85035647
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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}}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment