Skip to content

Commit e535adb

Browse files
committed
[clang] Fix issues on template class enum member redeclaration
1 parent 19f0524 commit e535adb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,12 +1627,17 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
16271627
// specialization causes the implicit instantiation of the declarations, but
16281628
// not the definitions of scoped member enumerations.
16291629
//
1630-
// DR1484 clarifies that enumeration definitions inside of a template
1630+
// DR1484 clarifies that enumeration definitions inside a template
16311631
// declaration aren't considered entities that can be separately instantiated
1632-
// from the rest of the entity they are declared inside of.
1632+
// from the rest of the entity they are declared inside.
16331633
if (isDeclWithinFunction(D) ? D == Def : Def && !Enum->isScoped()) {
1634-
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
1635-
InstantiateEnumDefinition(Enum, Def);
1634+
// Prevent redundant instantiation of the enumerator-definition if the
1635+
// definition has already been instantiated due to a prior
1636+
// opaque-enum-declaration.
1637+
if (PrevDecl == nullptr) {
1638+
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
1639+
InstantiateEnumDefinition(Enum, Def);
1640+
}
16361641
}
16371642

16381643
return Enum;

0 commit comments

Comments
 (0)