public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107624] New: Wrong code with static operator ()
@ 2022-11-10 21:42 jakub at gcc dot gnu.org
  2022-11-10 21:45 ` [Bug c++/107624] [c++23] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-10 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107624
           Summary: Wrong code with static operator ()
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

In:
struct S {
  static void operator() (int);
  static void baz (int);
};
S &foo (int);

void
bar ()
{
  foo (0) (0);
  foo (1).baz (1);
}
we transform the latter into *foo (1), S::baz (1), but the former into just
S::operator() (0) - the side-effects on the postfix-expression are gone.
Shouldn't we add that somewhere as COMPOUND_EXPR when we select a static
operator() (ditto for static operator[])?

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

* [Bug c++/107624] [c++23] Wrong code with static operator ()
  2022-11-10 21:42 [Bug c++/107624] New: Wrong code with static operator () jakub at gcc dot gnu.org
@ 2022-11-10 21:45 ` pinskia at gcc dot gnu.org
  2022-11-16 13:44 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-10 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is interesting because clang also does not produce a call for the foo
either for "foo (0) (0);".

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

* [Bug c++/107624] [c++23] Wrong code with static operator ()
  2022-11-10 21:42 [Bug c++/107624] New: Wrong code with static operator () jakub at gcc dot gnu.org
  2022-11-10 21:45 ` [Bug c++/107624] [c++23] " pinskia at gcc dot gnu.org
@ 2022-11-16 13:44 ` cvs-commit at gcc dot gnu.org
  2022-11-16 14:01 ` jakub at gcc dot gnu.org
  2022-11-28 22:23 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-16 13:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r13-4095-gcf958f8f168f695d49e29297ef9fb37f6efa5d0f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Nov 16 14:42:54 2022 +0100

    c++: Fix up calls to static operator() or operator[] [PR107624]

    One thing that doesn't work properly is the same problem as I've filed
    yesterday for static operator() - PR107624 - that side-effects of
    the postfix-expression on which the call or subscript operator are
    applied are thrown away, I assume we have to add them into COMPOUND_EXPR
    somewhere after we find out that the we've chosen a static member function
    operator.

    On Mon, Nov 14, 2022 at 06:29:44PM -0500, Jason Merrill wrote:
    > Indeed.  The code in build_new_method_call for this case has the comment
    >
    >               /* In an expression of the form `a->f()' where `f' turns
    >                  out to be a static member function, `a' is
    >                  none-the-less evaluated.  */

    Had to tweak 3 spots for this.  Furthermore, found that if in non-pedantic
    C++20 compilation static operator[] is accepted, we required that it has 2
    arguments, I think it is better to require exactly one because that case
    is the only one that will actually work in C++20 and older.

    2022-11-16  Jakub Jelinek  <jakub@redhat.com>

            PR c++/107624
            * call.cc (keep_unused_object_arg): New function.
            (build_op_call): Use it.
            (build_op_subscript): Likewise.
            (build_new_op): Similarly for ARRAY_REF.
            (build_new_method_call): Use it.
            * decl.cc (grok_op_properties): For C++20 and earlier, if
operator[]
            is static member function, require exactly one parameter rather
than
            exactly two parameters.

            * g++.dg/cpp23/static-operator-call4.C: New test.
            * g++.dg/cpp23/subscript10.C: New test.
            * g++.dg/cpp23/subscript11.C: New test.

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

* [Bug c++/107624] [c++23] Wrong code with static operator ()
  2022-11-10 21:42 [Bug c++/107624] New: Wrong code with static operator () jakub at gcc dot gnu.org
  2022-11-10 21:45 ` [Bug c++/107624] [c++23] " pinskia at gcc dot gnu.org
  2022-11-16 13:44 ` cvs-commit at gcc dot gnu.org
@ 2022-11-16 14:01 ` jakub at gcc dot gnu.org
  2022-11-28 22:23 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-11-16 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed now.

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

* [Bug c++/107624] [c++23] Wrong code with static operator ()
  2022-11-10 21:42 [Bug c++/107624] New: Wrong code with static operator () jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-11-16 14:01 ` jakub at gcc dot gnu.org
@ 2022-11-28 22:23 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-28 22:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0

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

end of thread, other threads:[~2022-11-28 22:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 21:42 [Bug c++/107624] New: Wrong code with static operator () jakub at gcc dot gnu.org
2022-11-10 21:45 ` [Bug c++/107624] [c++23] " pinskia at gcc dot gnu.org
2022-11-16 13:44 ` cvs-commit at gcc dot gnu.org
2022-11-16 14:01 ` jakub at gcc dot gnu.org
2022-11-28 22:23 ` pinskia 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).