public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations
@ 2015-01-20  1:30 rs2740 at gmail dot com
  2022-04-29 19:06 ` [Bug c++/64679] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: rs2740 at gmail dot com @ 2015-01-20  1:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64679
           Summary: Spurious redefinition error when parsing
                    not-quite-most-vexing-parse declarations
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com

Repro:

class Bar{
public:
  Bar(int, int, int);
};

int main () {
  int x = 1;
  Bar bar(int(x), int(x), int{x});
}

gcc HEAD 5.0.0 20150119 (experimental) with g++ prog.cc -Wall -Wextra
-std=gnu++1y reports:

prog.cc: In function 'int main()':
prog.cc:8:24: error: redefinition of 'int x'
  Bar bar(int(x), int(x), int{x});
                       ^
prog.cc:8:16: note: 'int x' previously declared here
  Bar bar(int(x), int(x), int{x});

With the last int{x} (note the braces) this cannot be a function declaration,
but g++ appears to emit the redefinition errors too early, before the full
declaration is parsed. Clang compiles this successfully.


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

* [Bug c++/64679] Spurious redefinition error when parsing not-quite-most-vexing-parse declarations
  2015-01-20  1:30 [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations rs2740 at gmail dot com
@ 2022-04-29 19:06 ` mpolacek at gcc dot gnu.org
  2022-05-04 20:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-29 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/64679] Spurious redefinition error when parsing not-quite-most-vexing-parse declarations
  2015-01-20  1:30 [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations rs2740 at gmail dot com
  2022-04-29 19:06 ` [Bug c++/64679] " mpolacek at gcc dot gnu.org
@ 2022-05-04 20:06 ` cvs-commit at gcc dot gnu.org
  2022-05-05 21:34 ` cvs-commit at gcc dot gnu.org
  2022-05-05 21:37 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-04 20:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:a733dea9e7c39352ce9f72059938833eaa819467

commit r13-121-ga733dea9e7c39352ce9f72059938833eaa819467
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Apr 29 15:01:12 2022 -0400

    c++: wrong parse with functors [PR64679]

    Consider

      struct F {
        F(int) {}
        F operator()(int) const { return *this; }
      };

    and

      F(i)(0)(0);

    where we're supposed to first call the constructor and then invoke
    the operator() twice.  However, we parse this as an init-declarator:
    "(i)" looks like a perfectly valid declarator, then we see an '(' and
    think it must be an initializer, so we commit and we're toast.  My
    fix is to look a little bit farther before deciding we've seen an
    initializer.

    This is only a half of c++/64679, the other part of the PR is unrelated:
    there the problem is that we are calling pushdecl while parsing
    tentatively (in cp_parser_parameter_declaration_list), which is bad.

            PR c++/64679

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_init_declarator): Properly handle a series
of
            operator() calls, they are not part of an init-declarator.

    gcc/testsuite/ChangeLog:

            * g++.dg/parse/functor1.C: New test.

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

* [Bug c++/64679] Spurious redefinition error when parsing not-quite-most-vexing-parse declarations
  2015-01-20  1:30 [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations rs2740 at gmail dot com
  2022-04-29 19:06 ` [Bug c++/64679] " mpolacek at gcc dot gnu.org
  2022-05-04 20:06 ` cvs-commit at gcc dot gnu.org
@ 2022-05-05 21:34 ` cvs-commit at gcc dot gnu.org
  2022-05-05 21:37 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-05 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:ee9128189623ce43343ce326caa8d5eec2eccfec

commit r13-146-gee9128189623ce43343ce326caa8d5eec2eccfec
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue May 3 19:01:19 2022 -0400

    c++: wrong error with MVP and pushdecl [PR64679]

    This patch fixes the second half of 64679.  Here we issue a wrong
    "redefinition of 'int x'" for the following:

      struct Bar {
        Bar(int, int, int);
      };

      int x = 1;
      Bar bar(int(x), int(x), int{x}); // #1

    cp_parser_parameter_declaration_list does pushdecl every time it sees
    a named parameter, so the second "int(x)" causes the error.  That's
    premature, since this turns out to be a constructor call after the
    third argument!

    If the first parameter is parenthesized, we can't push until we've
    established we're looking at a function declaration.  Therefore this
    could be fixed by some kind of lookahead.  I thought about introducing a
    lightweight variant of cp_parser_parameter_declaration_list that would
    not have any side effects and would return as soon as it figures out
    whether it's looking at a declaration or expression.  Since that would
    require fairly nontrivial changes, I wanted something simpler.

    Something like delaying the pushdecl until we've reached the ')'
    following the parameter-declaration-clause.  But we must push the
    parameters before processing a default argument, as in:

      Bar bar(int(a), int(b), int c = sizeof(a));  // valid

    Moreover, this code should still be accepted

      Bar f(int(i), decltype(i) j = 42);

    so this patch stashes parameters into a vector when parsing tentatively
    only when pushdecl-ing a parameter would result in a clash and an error
    about redefinition/redeclaration.  The stashed parameters are pushed at
    the end of a parameter-declaration-clause if it's followed by a ')', so
    that we still diagnose redefining a parameter.

            PR c++/64679

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_parameter_declaration_clause): Maintain
            a vector of parameters that haven't been pushed yet.  Push them at
the
            end of a valid parameter-declaration-clause.
            (cp_parser_parameter_declaration_list): Take a new auto_vec
parameter.
            Do not pushdecl while parsing tentatively when pushdecl-ing a
parameter
            would result in a hard error.
            (cp_parser_cache_defarg): Adjust the call to
            cp_parser_parameter_declaration_list.

    gcc/testsuite/ChangeLog:

            * g++.dg/parse/ambig11.C: New test.
            * g++.dg/parse/ambig12.C: New test.
            * g++.dg/parse/ambig13.C: New test.
            * g++.dg/parse/ambig14.C: New test.

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

* [Bug c++/64679] Spurious redefinition error when parsing not-quite-most-vexing-parse declarations
  2015-01-20  1:30 [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations rs2740 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-05-05 21:34 ` cvs-commit at gcc dot gnu.org
@ 2022-05-05 21:37 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-05 21:37 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13.

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

end of thread, other threads:[~2022-05-05 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20  1:30 [Bug c++/64679] New: Spurious redefinition error when parsing not-quite-most-vexing-parse declarations rs2740 at gmail dot com
2022-04-29 19:06 ` [Bug c++/64679] " mpolacek at gcc dot gnu.org
2022-05-04 20:06 ` cvs-commit at gcc dot gnu.org
2022-05-05 21:34 ` cvs-commit at gcc dot gnu.org
2022-05-05 21:37 ` mpolacek 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).