public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50330] New: Misleading error message with struct declaration
@ 2011-09-08 14:58 rui.maciel at gmail dot com
  2011-09-08 15:14 ` [Bug c/50330] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: rui.maciel at gmail dot com @ 2011-09-08 14:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50330

             Bug #: 50330
           Summary: Misleading error message with struct declaration
    Classification: Unclassified
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rui.maciel@gmail.com


struct t {
         int x;
}

int main(void)
{
         return 0;
}

This code, compiled with gcc, produces the following error message:

<message>
rui@Kubuntu:tmp$ gcc main.c
main.c:5:1: error: two or more data types in declaration specifiers
main.c: In function ‘main’:
main.c:7:10: error: incompatible types when returning type ‘int’ but ‘struct t’
was expected
</message>

The same code, when compiled with g++, produces the following error message:

<message>
rui@Kubuntu:tmp$ g++ main.c
main.c:1:1: error: new types may not be defined in a return type
main.c:1:1: note: (perhaps a semicolon is missing after the definition of ‘t’)
main.c:5:14: error: two or more data types in declaration of ‘main’
</message>

gcc's error message is cryptic and doesn't help the user.  g++'s error message,
on the other hand, although it is still cryptic it provides useful clues to the
user, which makes it considerably more helpful.  Nonetheless, both error
messages are needlessly cryptic and could be considerable improved, so that the
user gets a much clearer idea on where the error lies.

As a comparison, here is clang's error message:

<message>
rui@Kubuntu:tmp$ clang main.c
main.c:3:2: error: expected ';' after struct
}
 ^
 ;
1 error generated.
</message>

This error message is clear, concise and to the point. 

It would be great if GCC improved the error message for this scenario.


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

* [Bug c/50330] Misleading error message with struct declaration
  2011-09-08 14:58 [Bug c/50330] New: Misleading error message with struct declaration rui.maciel at gmail dot com
@ 2011-09-08 15:14 ` redi at gcc dot gnu.org
  2011-09-08 15:18 ` redi at gcc dot gnu.org
  2011-09-09  7:24 ` bugzilla at bsb dot me.uk
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-08 15:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50330

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-08 15:08:46 UTC ---
gcc 4.6 gives:
s.c:5:1: error: expected ';', identifier or '(' before 'int'

and g++ 4.6 gives:
s.c:3:1: error: expected ';' after struct definition


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

* [Bug c/50330] Misleading error message with struct declaration
  2011-09-08 14:58 [Bug c/50330] New: Misleading error message with struct declaration rui.maciel at gmail dot com
  2011-09-08 15:14 ` [Bug c/50330] " redi at gcc dot gnu.org
@ 2011-09-08 15:18 ` redi at gcc dot gnu.org
  2011-09-09  7:24 ` bugzilla at bsb dot me.uk
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2011-09-08 15:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50330

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |DUPLICATE

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-09-08 15:16:35 UTC ---
marking as dup instead of FIXED

*** This bug has been marked as a duplicate of bug 45331 ***


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

* [Bug c/50330] Misleading error message with struct declaration
  2011-09-08 14:58 [Bug c/50330] New: Misleading error message with struct declaration rui.maciel at gmail dot com
  2011-09-08 15:14 ` [Bug c/50330] " redi at gcc dot gnu.org
  2011-09-08 15:18 ` redi at gcc dot gnu.org
@ 2011-09-09  7:24 ` bugzilla at bsb dot me.uk
  2 siblings, 0 replies; 4+ messages in thread
From: bugzilla at bsb dot me.uk @ 2011-09-09  7:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50330

Ben Bacarisse <bugzilla at bsb dot me.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at bsb dot me.uk

--- Comment #3 from Ben Bacarisse <bugzilla at bsb dot me.uk> 2011-09-09 01:10:02 UTC ---
The fixed message (as reported) is not quite right.  It lists some, but not
all, of the tokens that are to be expected in this situation.  Basically, apart
from the semicolon, anything that can start a declarator is to be expected so
the list should include '*' as well.

I don't this is worth a new bug report, so I am just commenting here.


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

end of thread, other threads:[~2011-09-09  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-08 14:58 [Bug c/50330] New: Misleading error message with struct declaration rui.maciel at gmail dot com
2011-09-08 15:14 ` [Bug c/50330] " redi at gcc dot gnu.org
2011-09-08 15:18 ` redi at gcc dot gnu.org
2011-09-09  7:24 ` bugzilla at bsb dot me.uk

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).