https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88493
Bug ID: 88493
Summary: Inconsistent error messages for unknown types
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: ---
When compiling:
----8<----8<----8<----
struct Foo;
struct Bar
{
explicit Bar(Fooo* foo_) :
m_foo{foo_}
{
}
void Baz(Fooo* foo_);
Fooo* m_foo;
};
----8<----8<----8<----
Foo is forward declared, Fooo is not declared/defined, simulating a typo.
$ g++-8.2.1 -Wall -c 20181213-bad_type_name_diag.cpp
20181213-bad_type_name_diag.cpp:5:19: error: expected ‘)’ before ‘*’ token
explicit Bar(Fooo* foo_) :
~ ^
)
20181213-bad_type_name_diag.cpp:7:2: error: expected unqualified-id before ‘{’
token
{
^
20181213-bad_type_name_diag.cpp:10:11: error: ‘Fooo’ has not been declared
void Baz(Fooo* foo_);
^~~~
20181213-bad_type_name_diag.cpp:12:2: error: ‘Fooo’ does not name a type; did
you mean ‘Foo’?
Fooo* m_foo;
^~~~
Foo
The first error is not really helping, the second one is a cascade from that.
The third one is OK, but there is no suggestion. The fourth one is the most
useful.
For the three cases of Foo vs Fooo mismatch, three different error messages was
printed.
If I follow the suggestion of the first error msg, and put a ): after Fooo and
comment out the rest of the line:
$ g++-8.2.1 -Wall -c 20181213-bad_type_name_diag.cpp
20181213-bad_type_name_diag.cpp:5:19: error: function definition does not
declare parameters
explicit Bar(Fooo) : //* foo_) :
^
However, mentioning only the type of the parameter and not name it should be
accepted. Then, report an error because Fooo is unknown, possibly suggesting
Foo instead.
GCC 6/7/8/9 report the same errors, with minor formatting/coloring differences.
$ g++-8.2.1 -v
Using built-in specs.
COLLECT_GCC=g++-8.2.1
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure CC=gcc-8.2.1 CXX=g++-8.2.1
--enable-languages=c,c++ --disable-multilib --program-suffix=-8.2.1
--disable-bootstrap CFLAGS='-O2 -march=native -mtune=native' CXXFLAGS='-O2
-march=native -mtune=native'
Thread model: posix
gcc version 8.2.1 20181213 (GCC)
$ g++-9.0.0 -v
Using built-in specs.
COLLECT_GCC=g++-9.0.0
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure CC=gcc-8.2.1 CXX=g++-8.2.1
--enable-languages=c,c++ --disable-multilib --program-suffix=-9.0.0
--disable-bootstrap CFLAGS='-O2 -march=native -mtune=native' CXXFLAGS='-O2
-march=native -mtune=native'
Thread model: posix
gcc version 9.0.0 20181213 (experimental) (GCC)