This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49224] [C++0x] Scoped enumeration instantiated even if not required
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Aug 2017 13:39:38 +0000
- Subject: [Bug c++/49224] [C++0x] Scoped enumeration instantiated even if not required
- Auto-submitted: auto-generated
- References: <bug-49224-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49224
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Johannes Schaub from comment #0)
> GCC should not instantiate the definition of the scoped enumeration:
>
> template<typename T>
> struct A {
> enum class B {
> X = T::value
> };
> };
>
> int main() {
> A<int> a;
> }
>
> GCC error:
>
> main1.cpp: In instantiation of ‘A<int>’:
> main1.cpp:9:10: instantiated from here
> main1.cpp:3:14: error: ‘value’ is not a member of ‘int’
>
> This code looks well-formed. Only if we look into the enumeration, as
> "A<int>::B::X", the definition of the enumeration is required to exist and
> thus implicitly instantiated. This is specified at 14.7.1p1 and p2.
Confirmed that g++ rejects it, but clang rejects it too:
$ /usr/local/bin/g++ -c -Wall -Wextra -pedantic 49224.cc
49224.cc: In instantiation of ‘struct A<int>’:
49224.cc:9:9: required from here
49224.cc:3:13: error: ‘value’ is not a member of ‘int’
enum class B {
^
49224.cc: In function ‘int main()’:
49224.cc:9:9: warning: unused variable ‘a’ [-Wunused-variable]
A<int> a;
^
$ /sw/opt/llvm-3.1/bin/clang++ -c -Wall -Wextra -pedantic 49224.cc
49224.cc:3:7: error: expected identifier or '{'
enum class B {
^
49224.cc:3:2: warning: declaration does not declare anything
[-Wmissing-declarations]
enum class B {
^~~~
49224.cc:9:9: warning: unused variable 'a' [-Wunused-variable]
A<int> a;
^
2 warnings and 1 error generated.
$
Since I'm not sure if this is intentional or not, I'm leaving it UNCONFIRMED.