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

            Bug ID: 122417
           Summary: Improve diagnostic for shadowing typedef with a
                    declaration that uses type inference
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

Here are two programs which incorrectly shadow a typedef with a declaration
that uses type inference, and their error messages generated by GCC (<source>
is the name of the file on godbolt).

Program 1:

typedef int A;
int main(){
    auto A=0;
}

Error 1:

<source>:3:11: error: expected identifier or '(' before '=' token
    3 |     auto A=0;
      |           ^

Program 2:

typedef int B;
int main(){
    auto(B)=0;
}

Error 2:

<source>:3:10: error: expected identifier or '(' before 'B'
    3 |     auto(B)=0;
      |          ^

The message in error 1 is correct, but it would be helpful to point out
specifically here that this cannot declare A. Also a pointer operator * or
attribute specifier sequence [[...]] could validly occur after A (e.g. auto
A[[]]x=0;), so it's not even comprehensive either. The message in error 2 is
outright confusing, B is an identifier and the token before B is an opening
parenthesis. I think it is worth improving the error messages in both programs
to specifically mention that a typedef being visible with the same name
prevents type inference from being used.

Reply via email to