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

            Bug ID: 91119
           Summary: Bogus type re-difinition error
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: me at adhokshajmishraonline dot in
  Target Milestone: ---

Test code
---------

class A {};

class B {
    using C = A;

    enum D {
        A,
    };
};

When the above code is compiled using g++ (g++ -c test.cpp -o test.o), the
compiler produces the following output:

╭─ adhokshajmishra@andromeda  in /tmp 
╰─➤  g++ -c test.cpp -o test.o                                                  
test.cpp:7:9: error: declaration of ‘A’ changes meaning of ‘A’ [-fpermissive]
    7 |         A,
      |         ^
test.cpp:1:7: note: ‘A’ declared here as ‘class A’
    1 | class A {};
      |       ^

If the same code is compiled with clang, there is no error produced. The
following workaround seems to work:

class A {};

class B {
    using C = ::A;

    enum D {
        A,
    };
};

As far as I know, original test code is correct as per C++11 standard:

<quote>
A class name (9.1) or enumeration name (7.2) can be hidden by the name of a
variable, data member, function, or enumerator declared in the same scope. If a
class or enumeration name and a variable, data member, function, or enumerator
are declared in the same scope (in any order) with the same name, the class or
enumeration name is hidden wherever the variable, data member, function, or
enumerator name is visible.
</quote>

Reply via email to