Skip to content

Commit

Permalink
[Sema] Avoid crash in CheckEnumConstant with contains-error expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mccall committed Nov 2, 2021
1 parent 6fd2db0 commit 5880c83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/recovery-expr-type.cpp
Expand Up @@ -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}}
}

0 comments on commit 5880c83

Please sign in to comment.