Bug 88504 - Inconsistent error message notes when using forward-declared type as value
Summary: Inconsistent error message notes when using forward-declared type as value
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2018-12-14 22:19 UTC by petschy
Modified: 2018-12-17 12:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-12-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description petschy 2018-12-14 22:19:09 UTC
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