Skip to content

Commit 837da39

Browse files
authored
Check for redef enumerators in define_enum (#285)
Signed-off-by: acassagnes <acassagnes@bloomberg.net>
1 parent e52cb4c commit 837da39

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,9 @@ def p3385_sema_trace_execution_checkpoint : Warning<
32713271
def p3385_warn_unsupported_attribute : Error<
32723272
"reflecting over the unsupported '%0' attribute is ill-formed">;
32733273

3274+
// P4033
3275+
def p4033_sema_define_enum_enumerator : Error<"could not create enumerator %0">;
3276+
32743277
// C++11 char16_t/char32_t
32753278
def warn_cxx98_compat_unicode_type : Warning<
32763279
"'%0' type specifier is incompatible with C++98">,
@@ -12611,7 +12614,7 @@ def warn_zero_as_null_pointer_constant : Warning<
1261112614
InGroup<DiagGroup<"zero-as-null-pointer-constant">>, DefaultIgnore;
1261212615

1261312616
def warn_not_eliding_copy_on_return : Warning<
12614-
"not eliding copy on return">,
12617+
"not eliding copy on return">,
1261512618
InGroup<DiagGroup<"nrvo">>, DefaultIgnore;
1261612619

1261712620
def err_nullability_cs_multilevel : Error<

clang/lib/AST/ExprConstantMeta.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,6 +5867,9 @@ bool define_enum(APValue &Result, ASTContext &C, MetaActions &Meta,
58675867
EnumDecl *completedEnum =
58685868
Meta.DefineEnum(foundDecl, EnumSpecs, ContainingDecl,
58695869
TargetEnum, nullptr, Args[0]->getExprLoc());
5870+
if (!completedEnum) {
5871+
return true;
5872+
}
58705873
return SetAndSucceed(Result, makeReflection(completedEnum));
58715874
}
58725875

clang/lib/Sema/SemaReflect.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ class MetaActionsImpl : public MetaActions {
529529
Decl *EnumConstDecl =
530530
S.ActOnEnumConstant(&EnumScope, ED, LastEnumConstDecl, DefinitionLoc,
531531
II, attrs, DefinitionLoc, Val);
532+
if (!EnumConstDecl) {
533+
// TODO any rollback we need to do ?...
534+
S.Diag(DefinitionLoc, diag::p4033_sema_define_enum_enumerator) << enumSpec->name;
535+
return nullptr;
536+
}
532537

533538
// Attach annotations as CXX26AnnotationAttr directly on the decl.
534539
for (APValue *annotVal : enumSpec->annotations) {

0 commit comments

Comments
 (0)