diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -406,6 +406,9 @@ when it had been instantiated from a partial template specialization with different template arguments on the containing class. This fixes: (`#60778 `_). +- Fix a crash when an enum constant has a dependent-type recovery expression for + C. + (`#62446 `_). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -19307,6 +19307,7 @@ if (!getLangOpts().CPlusPlus && !T.isNull()) Diag(IdLoc, diag::warn_enum_value_overflow); } else if (!getLangOpts().CPlusPlus && + !EltTy->isDependentType() && !isRepresentableIntegerValue(Context, EnumVal, EltTy)) { // Enforce C99 6.7.2.2p2 even when we compute the next value. Diag(IdLoc, diag::ext_enum_value_not_int) diff --git a/clang/test/AST/ast-dump-recovery.c b/clang/test/AST/ast-dump-recovery.c --- a/clang/test/AST/ast-dump-recovery.c +++ b/clang/test/AST/ast-dump-recovery.c @@ -98,3 +98,14 @@ // CHECK-NEXT: `-RecoveryExpr {{.*}} '' ext(undef_var); } + +// Verify no crash. +void test4() { + enum GH62446 { + // CHECK: RecoveryExpr {{.*}} '' contains-errors lvalue + // CHECK-NEXT: |-StringLiteral {{.*}} "a" + // CHECK-NEXT: `-IntegerLiteral {{.*}} 2 + invalid_enum_value = "a" * 2, + b, + }; +}