[Bug c++/83469] New: union is not accepted as a valid class-key in template name resolution

smw at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 18 19:01:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83469

            Bug ID: 83469
           Summary: union is not accepted as a valid class-key in template
                    name resolution
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: smw at gcc dot gnu.org
  Target Milestone: ---

The following code is accepted by clang, icc, and msvc (all versions tested)
but is rejected with all version of GCC (tested from 4.0 though 7.1).

    struct S {
        union U { int m; };
    };

    template <typename T>
      void f()
      { union T::U u; }

    int
    main()
    {
      f<S>();
    }

The compilation error is as follows.

    $ g++ -Wall -Wextra -pedantic -o tun tun.cpp
    tun.cpp: In function ‘void f()’:
    tun.cpp:7:14: error: ‘union’ tag used in naming ‘class T::U’ [-fpermissive]
       { union T::U u; }
              ^
    tun.cpp:7:14: note: ‘class T::U’ was previously declared here
    tun.cpp: In instantiation of ‘void f() [with T = S]’:
    tun.cpp:12:8:   required from here

Note that nothing in ISO/IEC 14882:2014 16.6/5 [temp.res] implies the class-key
'union' should be treated differently than the class-key 'struct' or 'class'
when resolving qualified names.


More information about the Gcc-bugs mailing list