summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2020-01-13 07:45:17 -0800
committerErich Keane <erich.keane@intel.com>2020-01-13 13:51:48 -0800
commitf0719bf2196c807351137ff30e39fd12aa5aa884 (patch)
treeb7e27fafe932e1ad5c6bcf5cf58e09aaddd48e84 /clang
parent31441a3e007833a180b0112550eddb78547771f2 (diff)
downloadbcm5719-llvm-f0719bf2196c807351137ff30e39fd12aa5aa884.tar.gz
bcm5719-llvm-f0719bf2196c807351137ff30e39fd12aa5aa884.zip
PR44514: Fix recovery from noexcept with non-convertible expressions
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaExceptionSpec.cpp12
-rw-r--r--clang/test/SemaCXX/cxx0x-noexcept-expression.cpp5
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index 959cdadad87..5aedbe7644e 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -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;
diff --git a/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp b/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
index cbee30003b2..f1c6d590bfb 100644
--- a/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ b/clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -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());
+};
OpenPOWER on IntegriCloud