Issue 124405
Summary Duplicated instantiation of enumerators cause ambiguous references to the same name
Labels new issue
Assignees
Reporter thebrandre
    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/5KnE9K8G4)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to