[Bug c/55613] New: Better warning for reference to struct type
rui.maciel at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Dec 7 11:58:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55613
Bug #: 55613
Summary: Better warning for reference to struct type
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rui.maciel@gmail.com
Consider the following code:
<code>
struct Foo
{
int i;
};
int main(void)
{
Foo foo;
return 0;
}
</code>
When compiled with gcc 4.6.3, the following error message is displayed:
<message>
main.c: In function ‘main’:
main.c:8:2: error: unknown type name ‘Foo’
</message>
The problem with this code is that Foo isn't preceded by the keyword "struct".
Yet, as the compiler only returns a vague message about Foo being an unknown
type name, it may mislead the programmer into assuming that the problem might
lie somewhere else, such as a typo somewhere, particularly if the code contains
a significant number of typedef structs.
A significantly better way to handle this error is to warn that the "struct"
keyword is missing. This happens to be the way other compilers, such as clang,
handle this error. The following is clang's error message for this scenario:
<message>
main.c:8:2: error: must use 'struct' tag to refer to type 'Foo'
Foo foo;
^
struct
1 error generated.
</message>
It would be great if gcc improved its error diagnostics for this error.
More information about the Gcc-bugs
mailing list