public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/52987] New: bogus expected ; before for undeclared type
Date: Sat, 14 Apr 2012 15:23:00 -0000	[thread overview]
Message-ID: <bug-52987-4@http.gcc.gnu.org/bugzilla/> (raw)

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. :-(


             reply	other threads:[~2012-04-14 15:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-14 15:23 manu at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-52987-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).