[PATCH] D72621: PR44514: Fix recovery from noexcept with non-convertible expressions
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 13 08:22:14 PST 2020
erichkeane created this revision.
erichkeane added a reviewer: aaron.ballman.
Herald added a project: clang.
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.
Repository:
rC Clang
https://reviews.llvm.org/D72621
Files:
clang/lib/Sema/SemaExceptionSpec.cpp
clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===================================================================
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -75,3 +75,8 @@
static_assert(!noexcept((int(*)[b ? throw : 42])0), "");
static_assert(!noexcept((int(*)[b ? throw : 42]){0}), "");
}
+
+struct pr_44514 {
+ // expected-error at +1{{value of type 'void' is not contextually convertible to 'bool'}}
+ void foo(void) const &noexcept(f());
+};
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -81,8 +81,16 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72621.237686.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200113/60c2a7fe/attachment.bin>
More information about the cfe-commits
mailing list