<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124405>124405</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Duplicated instantiation of enumerators cause ambiguous references to the same name
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thebrandre
</td>
</tr>
</table>
<pre>
Clang erroneously instantiates the enumerators twice in the case of a prior declaration.
As a consequence, the name lookup in the last line of the following example becomes ambiguous.
```cpp
template <typename T>
struct S {
enum E : T;
enum E : T { X = 5 };
};
auto x = S<char>::X;
```
Compiler output:
```
source>:7:19: error: reference to 'X' is ambiguous
7 | auto x = S<char>::X;
| ~~~~~~~~~^
<source>:4:18: note: candidate found by name lookup is 'S<char>::X'
4 | enum E : T { X = 5 };
| ^
<source>:4:18: note: candidate found by name lookup is 'S<char>::X'
1 error generated.
```
Another symptom is that diagnostics during instantiation appear twice in the output if a preceding opaque-enum-declaration exists:
```cpp
template <typename T>
struct S {
enum E : T;
enum E : T { X = 0x7FFFFF00 };
};
template struct S<char>;
```
Compiler output:
```
<source>:4:22: warning: implicit conversion from 'int' to 'char' changes value from 2147483392 to 0 [-Wconstant-conversion]
4 | enum E : T { X = 0x7FFFFF00 };
| ^~~~~~~~~~
<source>:7:17: note: in instantiation of template class 'S<char>' requested here
7 | template struct S<char>;
| ^
<source>:4:22: error: enumerator value evaluates to 2147483392, which cannot be narrowed to type 'char' [-Wc++11-narrowing]
4 | enum E : T { X = 0x7FFFFF00 };
| ^
<source>:4:22: warning: implicit conversion from 'int' to 'char' changes value from 2147483392 to 0 [-Wconstant-conversion]
4 | enum E : T { X = 0x7FFFFF00 };
| ^~~~~~~~~~
<source>:4:22: error: enumerator value evaluates to 2147483392, which cannot be narrowed to type 'char' [-Wc++11-narrowing]
2 warnings and 2 errors generated.
```
See [here on Compiler Explorer](https://godbolt.org/z/5KnE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