Skip to content

Commit

Permalink
PR44514: Fix recovery from noexcept with non-convertible expressions
Browse files Browse the repository at this point in the history
We currently treat noexcept(not-convertible-to-bool) as 'none', which
results in the typeloc info being a different size, and causing an
assert later on in the process.  In order to make recovery less
destructive, replace this with noexcept(false) and a constructed 'false'
expression.

Bug Report: https://bugs.llvm.org/show_bug.cgi?id=44514

Differential Revision: https://reviews.llvm.org/D72621
  • Loading branch information
Erich Keane committed Jan 13, 2020
1 parent 31441a3 commit f0719bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions clang/lib/Sema/SemaExceptionSpec.cpp
Expand Up @@ -81,8 +81,16 @@ ExprResult Sema::ActOnNoexceptSpec(SourceLocation NoexceptLoc,
ExceptionSpecificationType &EST) {
// FIXME: This is bogus, a noexcept expression is not a condition.
ExprResult Converted = CheckBooleanCondition(NoexceptLoc, NoexceptExpr);
if (Converted.isInvalid())
return Converted;
if (Converted.isInvalid()) {
EST = EST_NoexceptFalse;

// Fill in an expression of 'false' as a fixup.
auto *BoolExpr = new (Context)
CXXBoolLiteralExpr(false, Context.BoolTy, NoexceptExpr->getBeginLoc());
llvm::APSInt Value{1};
Value = 0;
return ConstantExpr::Create(Context, BoolExpr, APValue{Value});
}

if (Converted.get()->isValueDependent()) {
EST = EST_DependentNoexcept;
Expand Down
5 changes: 5 additions & 0 deletions clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
Expand Up @@ -75,3 +75,8 @@ void vla(bool b) {
static_assert(!noexcept((int(*)[b ? throw : 42])0), "");
static_assert(!noexcept((int(*)[b ? throw : 42]){0}), "");
}

struct pr_44514 {
// expected-error@+1{{value of type 'void' is not contextually convertible to 'bool'}}
void foo(void) const &noexcept(f());
};

0 comments on commit f0719bf

Please sign in to comment.