[Bug c++/101524] New: Improve diagnostic for incorrect definition of namespace alias

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jul 20 10:18:25 GMT 2021


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

            Bug ID: 101524
           Summary: Improve diagnostic for incorrect definition of
                    namespace alias
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

This is an incorrect attempt to define a namespace alias:

namespace x { namespace y { } }
using z = x::y;

GCC correctly says:

alias.C:2:14: error: ‘y’ in namespace ‘x’ does not name a type
    2 | using z = x::y;
      |              ^
alias.C:1:25: note: ‘x::y’ declared here
    1 | namespace x { namespace y { } }
      |                         ^

It might be nice in this case (where a using-declaration names a namespace, not
a type) to offer a fix-it to make it a namespace alias:

note: did you mean to define a namespace alias?
    2 | using z = x::y;
      | ^~~~~
      | namespace

The suggestion won't always be correct, maybe the user meant to define a
typedef for a type x::Y or x::yo and the x::y was a typo. And given how rarely
namespace aliases are used, maybe that's more likely. But maybe it's worth
doing.


More information about the Gcc-bugs mailing list