https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113342
Bug ID: 113342
Summary: Template parameter does not shadow member enum value.
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: courteauxmartijn at gmail dot com
Target Milestone: ---
Consider the boolean template parameter named "GPU" (think: the "Ref"
references something on a GPU):
template<bool GPU>
struct Ref {};
struct Job{
enum Device { CPU, GPU };
template<bool GPU>
void create(Ref<GPU> ref);
};
template<bool GPU>
void Job::create(Ref<GPU> ref) {}
The Job::Device enum has as second value "GPU". The implementation on the last
line of Job::create(Ref<GPU> ref) treats GPU as this second enum value, instead
of the boolean template argument. I believe the existence of the template
argument named "GPU" should shadow the enum value. However, the compiler
outputs this:
<source>:12:6: error: no declaration matches 'void Job::create(Ref<true>)'
12 | void Job::create(Ref<GPU> ref) {}
| ^~~
<source>:8:10: note: candidate is: 'template<bool GPU> void
Job::create(Ref<GPU>)'
8 | void create(Ref<GPU> ref);
| ^~~~~~
<source>:4:8: note: 'struct Job' defined here
4 | struct Job{
| ^~~
Notice in the first line that it treated the GPU as a "true", which would
originate from the fact that CPU has value 0, and GPU value 1 in that enum,
which gets converted to a bool implicitly.
https://godbolt.org/z/ro9hPvsz3
(Clang does compile this example as I expect it.)