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

            Bug ID: 124412
           Summary: different and confusing diagnostic order for = 0 / =
                    0u inside class vs at namespace scope
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

I noticed an interesting inconsistency in the diagnostic ordering when using =
0 and = 0u after function declarations inside a class vs at namespace scope.

Inside the class, the error order is reversed, while at global scope the order
looks correct. Other compilers do not show this kind of behavior.

code:
==============================
class A {
  void h() = 0;
  void j() = 0u;
};

void h() = 0;
void j() = 0u;
==============================

GCC outputs:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:3:16: error: invalid pure specifier (only '= 0' is allowed) before ';'
token
    3 |   void j() = 0u;
      |                ^
<source>:2:8: error: initializer specified for non-virtual method 'void A::h()'
    2 |   void h() = 0;
      |        ^
<source>:6:6: error: function 'void h()' is initialized like a variable
    6 | void h() = 0;
      |      ^
<source>:7:14: error: invalid pure specifier (only '= 0' is allowed) before ';'
token
    7 | void j() = 0u;
      |              ^
<source>:7:6: error: function 'void j()' is initialized like a variable
    7 | void j() = 0u;
      |      ^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to