public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/55613] New: Better warning for reference to struct type
@ 2012-12-07 11:58 rui.maciel at gmail dot com
  2012-12-09  0:34 ` [Bug c/55613] Add suggestion of adding struct if the name exists in the struct tag pinskia at gcc dot gnu.org
  2015-09-17 23:34 ` manu at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: rui.maciel at gmail dot com @ 2012-12-07 11:58 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-17 23:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-07 11:58 [Bug c/55613] New: Better warning for reference to struct type rui.maciel at gmail dot com
2012-12-09  0:34 ` [Bug c/55613] Add suggestion of adding struct if the name exists in the struct tag pinskia at gcc dot gnu.org
2015-09-17 23:34 ` manu at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).