public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113342] New: Template parameter does not shadow member enum value.
@ 2024-01-11 22:53 courteauxmartijn at gmail dot com
2024-01-11 22:58 ` [Bug c++/113342] " pinskia at gcc dot gnu.org
2024-01-11 23:00 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: courteauxmartijn at gmail dot com @ 2024-01-11 22:53 UTC (permalink / raw)
To: gcc-bugs
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.)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113342] Template parameter does not shadow member enum value.
2024-01-11 22:53 [Bug c++/113342] New: Template parameter does not shadow member enum value courteauxmartijn at gmail dot com
@ 2024-01-11 22:58 ` pinskia at gcc dot gnu.org
2024-01-11 23:00 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-11 22:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113342
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note MSVC has the same behavior as GCC here:
```
<source>(13): error C2244: 'Job::create': unable to match function definition
to an existing declaration
<source>(13): note: see declaration of 'Job::create'
<source>(13): note: definition
<source>(13): note: 'void Job::create(Ref<true>)'
<source>(13): note: existing declarations
<source>(13): note: 'void Job::create(Ref<GPU>)'
```
This is most likely related to
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html paper.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113342] Template parameter does not shadow member enum value.
2024-01-11 22:53 [Bug c++/113342] New: Template parameter does not shadow member enum value courteauxmartijn at gmail dot com
2024-01-11 22:58 ` [Bug c++/113342] " pinskia at gcc dot gnu.org
@ 2024-01-11 23:00 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-11 23:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113342
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note there was a change between `clang 10` and `clang 11` which changed clang
into accepting the code. So I am 99% sure it is that paper which caused the
change ...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-11 23:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 22:53 [Bug c++/113342] New: Template parameter does not shadow member enum value courteauxmartijn at gmail dot com
2024-01-11 22:58 ` [Bug c++/113342] " pinskia at gcc dot gnu.org
2024-01-11 23:00 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).