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

            Bug ID: 117894
           Summary: Elaborated-type-specifier with class/struct
                    incorrectly accepts union type when using a dependent
                    name
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

The following code is incorrectly accepted by GCC:

struct A{
    union B{};
};
template<typename T>void foo(T){
    struct T::B b;
}
int main(){
    foo(A());
}

In an elaborated-type-specifier, if the class-key used is class/struct then the
class shall be a non-union class and if the class-key used is union then the
class shall be a union. However, specifically with a dependent name and when
using class/struct GCC does not seem to follow this. Clang, MSVC, and EDG all
seem to reject this code. GCC rejects this code if the declaration of b is
changed to not use the dependent name (replacing T with A), or if the choice of
union and struct is swapped (swapping union with the struct in struct T::B).
  • [Bug c++/117894] New: Elaborated... luigighiron at gmail dot com via Gcc-bugs

Reply via email to