Bug 97531 - Improve type/non-type declaration diagnostic
Summary: Improve type/non-type declaration diagnostic
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-10-22 15:27 UTC by Marek Polacek
Modified: 2020-10-25 22:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-10-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2020-10-22 15:27:26 UTC
For this:

struct A { };
struct B { B(A); };

void
fn ()
{
  B(A()); // extern struct B A (void);
  A a;
}

we issue:
q.C: In function ‘void fn()’:
q.C:8:4: error: expected ‘;’ before ‘a’
    8 |   A a;
      |    ^~
      |    ;

Eh, what?

clang++:
q.C:8:3: error: must use 'struct' tag to refer to type 'A' in this scope
  A a;
  ^
  struct 
q.C:7:5: note: struct 'A' is hidden by a non-type declaration of 'A' here
  B(A()); // extern struct B A (void);
    ^
Comment 1 Marek Polacek 2020-10-25 22:32:53 UTC
Extended test:

// PR c++/97531

struct A { };
void A(int);

void
fn0 ()
{
  A a;
  static A *a2;
}

int B;
struct B { };

void
fn1 ()
{
  B b;
  static B *b2;
}

enum E { };
void E();

void
fn2 ()
{
  E e;
  static E *e2;
}

class C { };
void C(int);

void
fn3 ()
{
  C c;
  static C *c2;
}

union U { };
void U(int);

void
fn4 ()
{
  U u;
  static U *u2;
}