public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52987] New: bogus expected ; before for undeclared type
@ 2012-04-14 15:23 manu at gcc dot gnu.org
  2012-04-24  4:24 ` [Bug c++/52987] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-14 15:23 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52987
           Summary: bogus expected ; before for undeclared type
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: manu@gcc.gnu.org


void foo(void) {
  x var;
}

manuel@gcc12:~/test2$ ~/trunk/186353/build/gcc/cc1plus ~/notdeclared.c 
 void foo()
/home/manuel/notdeclared.c:2:3: error: ‘x’ was not declared in this scope
   x var;
   ^
/home/manuel/notdeclared.c:2:5: error: expected ‘;’ before ‘var’
   x var;
     ^

manuel@gcc12:~/test2$ clang ~/notdeclared.c 
/home/manuel/notdeclared.c:2:3: error: use of undeclared identifier 'x'
  x var;
  ^
1 error generated.

The "expected ";" before "var"" is bogus.

The following patch removes it in this case:


--- gcc/cp/parser.c     (revision 186353)
+++ gcc/cp/parser.c     (working copy)
@@ -5589,13 +5589,19 @@ cp_parser_postfix_expression (cp_parser 
   while (true)
     {
       if (idk == CP_ID_KIND_UNQUALIFIED
          && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
          && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
-       /* It is not a Koenig lookup function call.  */
-       postfix_expression
-         = unqualified_name_lookup_error (postfix_expression);
+       {
+         /* It is not a Koenig lookup function call.  */
+         postfix_expression = 
+           unqualified_name_lookup_error (postfix_expression);
+         /* It is better to skip the rest and return here, because at
+            this point we don't know what this statement is.   */
+         cp_parser_skip_to_end_of_statement (parser);
+         return error_mark_node;
+       }

       /* Peek at the next token.  */
       token = cp_lexer_peek_token (parser->lexer);

       switch (token->type)


Unfortunately, undeclared names can occur in many places besides statements, so
it fails for things like:

int foo(x var) {
}

I couldn't figure out how tell the context where we are called. :-(


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

* [Bug c++/52987] bogus expected ; before for undeclared type
  2012-04-14 15:23 [Bug c++/52987] New: bogus expected ; before for undeclared type manu at gcc dot gnu.org
@ 2012-04-24  4:24 ` pinskia at gcc dot gnu.org
  2013-07-11  9:49 ` paolo.carlini at oracle dot com
  2015-07-23 10:12 ` paolo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-04-24  4:24 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-24
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-04-24 04:23:33 UTC ---
Confirmed.  The C front-end handles this much better:
t.c: In function ‘foo’:
t.c:2:3: error: unknown type name ‘x’
   x var;
   ^


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

* [Bug c++/52987] bogus expected ; before for undeclared type
  2012-04-14 15:23 [Bug c++/52987] New: bogus expected ; before for undeclared type manu at gcc dot gnu.org
  2012-04-24  4:24 ` [Bug c++/52987] " pinskia at gcc dot gnu.org
@ 2013-07-11  9:49 ` paolo.carlini at oracle dot com
  2015-07-23 10:12 ` paolo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-11  9:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
The first half is fixed for 4.9.0 (r200150).


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

* [Bug c++/52987] bogus expected ; before for undeclared type
  2012-04-14 15:23 [Bug c++/52987] New: bogus expected ; before for undeclared type manu at gcc dot gnu.org
  2012-04-24  4:24 ` [Bug c++/52987] " pinskia at gcc dot gnu.org
  2013-07-11  9:49 ` paolo.carlini at oracle dot com
@ 2015-07-23 10:12 ` paolo at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-07-23 10:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52987

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Thu Jul 23 10:11:48 2015
New Revision: 226097

URL: https://gcc.gnu.org/viewcvs?rev=226097&root=gcc&view=rev
Log:
/cp
2015-07-23  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/52987
        * parser.c (cp_parser_simple_declaration): Robustify check avoiding
        redundant error messages.

/testsuite
2015-07-23  Paolo Carlini  <paolo.carlini@oracle.com>

        PR c++/52987
        * g++.dg/parse/error57.C: New.
        * g++.dg/expr/string-2.C: Update.

Added:
    trunk/gcc/testsuite/g++.dg/parse/error57.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/expr/string-2.C


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

end of thread, other threads:[~2015-07-23 10:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 15:23 [Bug c++/52987] New: bogus expected ; before for undeclared type manu at gcc dot gnu.org
2012-04-24  4:24 ` [Bug c++/52987] " pinskia at gcc dot gnu.org
2013-07-11  9:49 ` paolo.carlini at oracle dot com
2015-07-23 10:12 ` paolo 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).