[clang] 5880c83 - [Sema] Avoid crash in CheckEnumConstant with contains-error expressions
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 2 07:36:00 PDT 2021
Author: Sam McCall
Date: 2021-11-02T15:35:53+01:00
New Revision: 5880c835bdbe50542a19c3e4065d1536db711443
URL: https://github.com/llvm/llvm-project/commit/5880c835bdbe50542a19c3e4065d1536db711443
DIFF: https://github.com/llvm/llvm-project/commit/5880c835bdbe50542a19c3e4065d1536db711443.diff
LOG: [Sema] Avoid crash in CheckEnumConstant with contains-error expressions
Fixes https://bugs.llvm.org/show_bug.cgi?id=51554
Differential Revision: https://reviews.llvm.org/D108451
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8228292a3153a..d9844f18e1cf9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17813,7 +17813,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
Val = DefaultLvalueConversion(Val).get();
if (Val) {
- if (Enum->isDependentType() || Val->isTypeDependent())
+ if (Enum->isDependentType() || Val->isTypeDependent() ||
+ Val->containsErrors())
EltTy = Context.DependentTy;
else {
// FIXME: We don't allow folding in C++11 mode for an enum with a fixed
diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp
index 15b83e50387f7..2fdbd0d3b6c30 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -143,3 +143,11 @@ int fun(int *foo = no_such_function()); // expected-error {{undeclared identifie
void crash1() { fun(); }
void crash2() { constexpr int s = fun(); }
} // namespace test12
+
+namespace test13 {
+enum Circular { // expected-note {{not complete until the closing '}'}}
+ Circular_A = Circular(1), // expected-error {{'test13::Circular' is an incomplete type}}
+};
+// Enumerators can be evaluated (they evaluate as zero, but we don't care).
+static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static_assert failed}}
+}
More information about the cfe-commits
mailing list