[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 13:52:54 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0719bf2196c: PR44514: Fix recovery from noexcept with non-convertible expressions (authored by erichkeane).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72621/new/

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.237773.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200113/1e27e61b/attachment.bin>


More information about the cfe-commits mailing list