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

            Bug ID: 95871
           Summary: Duplicated error message : "the value is not usable in
                    a constant expression"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
                CC: mpolacek at gcc dot gnu.org
  Target Milestone: ---

This code, bug.cc, GCC emits two duplicated error messages in "the value of ‘a’
is not usable in a constant expression".

$cat bug.cc
long a = 10;
enum E { emator_1 = a } enum_var;

$g++ -c bug.cc
bug.cc:2:21: error: the value of ‘a’ is not usable in a constant expression
    2 | enum E { emator_1 = a } enum_var;
      |                     ^
bug.cc:1:6: note: ‘long int a’ is not const
    1 | long a = 10;
      |      ^
bug.cc:2:21: error: the value of ‘a’ is not usable in a constant expression
    2 | enum E { emator_1 = a } enum_var;
      |                     ^
bug.cc:1:6: note: ‘long int a’ is not const
    1 | long a = 10;
      |      ^
bug.cc:2:21: error: enumerator value for ‘emator_1’ is not an integer constant
    2 | enum E { emator_1 = a } enum_var;
      |   

While in clang
$clang++ -c bug.cc
bug.cc:2:21: error: expression is not an integral constant expression
enum E { emator_1 = a } enum_var;
                    ^
bug.cc:2:21: note: read of non-const variable 'a' is not allowed in a constant
expression
bug.cc:1:6: note: declared here
long a = 10;
     ^
1 error generated.

I have tested in almost all GCC versions, they all have this issue.

Reply via email to