https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88504
Bug ID: 88504 Summary: Inconsistent error message notes when using forward-declared type as value Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: petschy at gmail dot com Target Milestone: --- struct Foo; struct Bar { Bar(Foo f_) : m_foo(f_) { } Foo m_foo; }; Foo baz1() { } void baz2(Foo f_) { } void baz3() { Foo foo; } Foo g_foo; $ g++-9.0.0 -Wall -Wextra -c 20181214-fwddecl_value.cpp 20181214-fwddecl_value.cpp:10:6: error: field ‘m_foo’ has incomplete type ‘Foo’ 10 | Foo m_foo; | ^~~~~ 20181214-fwddecl_value.cpp:1:8: note: forward declaration of ‘struct Foo’ 1 | struct Foo; | ^~~ 20181214-fwddecl_value.cpp:5:10: error: ‘f_’ has incomplete type 5 | Bar(Foo f_) : | ~~~~^~ 20181214-fwddecl_value.cpp:1:8: note: forward declaration of ‘struct Foo’ 1 | struct Foo; | ^~~ 20181214-fwddecl_value.cpp:13:10: error: return type ‘struct Foo’ is incomplete 13 | Foo baz1() | ^ 20181214-fwddecl_value.cpp:17:15: error: ‘f_’ has incomplete type 17 | void baz2(Foo f_) | ~~~~^~ 20181214-fwddecl_value.cpp:1:8: note: forward declaration of ‘struct Foo’ 1 | struct Foo; | ^~~ 20181214-fwddecl_value.cpp: In function ‘void baz2(Foo)’: 20181214-fwddecl_value.cpp:17:15: warning: unused parameter ‘f_’ [-Wunused-parameter] 17 | void baz2(Foo f_) | ~~~~^~ 20181214-fwddecl_value.cpp: In function ‘void baz3()’: 20181214-fwddecl_value.cpp:23:6: error: aggregate ‘Foo foo’ has incomplete type and cannot be defined 23 | Foo foo; | ^~~ 20181214-fwddecl_value.cpp: At global scope: 20181214-fwddecl_value.cpp:26:5: error: aggregate ‘Foo g_foo’ has incomplete type and cannot be defined 26 | Foo g_foo; | ^~~~~ Most messages contain the note where the forward decl occured, but some don't: - returning from baz1() - local variable 'foo' in baz3() - global variable 'g_foo' Mentioning it everywhere would be helpful. Quite a minor issue, but the wording of the error messages also varies somewhat: - inside the class: field ‘m_foo’ has incomplete type ‘Foo’ - as fn param, the name of the type is omitted : ‘f_’ has incomplete type - when returning, 'struct Foo' is mentioned: return type ‘struct Foo’ is incomplete - but when defining a variable, Foo is not a struct, but an aggregate: aggregate ‘Foo foo’ has incomplete type and cannot be defined