public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96227] New: Comma operation sequencing issue
@ 2020-07-16 21:47 matt at godbolt dot org
  2021-07-16 23:47 ` [Bug c++/96227] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: matt at godbolt dot org @ 2020-07-16 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96227
           Summary: Comma operation sequencing issue
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
  Target Milestone: ---

Filing on behalf of @lunasorcery (on twitter):

The following code:

```
#include <cstdio>

struct S {
    S(char const* message) {
        puts(message);
    }
};
void operator,(S,S){}

int main() {
    S("first"), S("second");

    operator,(S("FIRST"), S("SECOND"));
}
```

Should produce the output:

first
second
FIRST
SECOND

But instead produces:

second
first
SECOND
FIRST


quotations from N4861:

[expr.comma]
"The left expression is sequenced before the right expression."

[over.match.oper]
"If either operand has a type that is a class or an enumeration,
a user-defined operator function might be declared that implements this
operator [...]
However, the operands are sequenced in the order prescribed for the built-in
operator."

[expr.call]
"If an operator function is invoked using operator notation, argument
evaluation is
sequenced as specified for the built-in operator; see 12.4.1.2."


https://gcc.godbolt.org/z/fdTG8q

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

* [Bug c++/96227] Comma operation sequencing issue
  2020-07-16 21:47 [Bug c++/96227] New: Comma operation sequencing issue matt at godbolt dot org
@ 2021-07-16 23:47 ` pinskia at gcc dot gnu.org
  2021-07-16 23:51 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-16 23:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-07-16
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, Note this was partly fixed with the fix for PR 82959.
That is not invoked as a function case has been fixed for GCC 8.5.

On the trunk we produce as of today:
first
second
SECOND
FIRST

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

* [Bug c++/96227] Comma operation sequencing issue
  2020-07-16 21:47 [Bug c++/96227] New: Comma operation sequencing issue matt at godbolt dot org
  2021-07-16 23:47 ` [Bug c++/96227] " pinskia at gcc dot gnu.org
@ 2021-07-16 23:51 ` pinskia at gcc dot gnu.org
  2021-07-17  7:36 ` jakub at gcc dot gnu.org
  2022-12-19 21:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-16 23:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Confirmed, Note this was partly fixed with the fix for PR 82959.
> That is not invoked as a function case has been fixed for GCC 8.5.
> 
> On the trunk we produce as of today:
> first
> second
> SECOND
> FIRST

I actually think this is still correct output as the function call version is
not mentioned in "If an operator function is invoked using operator notation"
here.

Am I reading this correctly?

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

* [Bug c++/96227] Comma operation sequencing issue
  2020-07-16 21:47 [Bug c++/96227] New: Comma operation sequencing issue matt at godbolt dot org
  2021-07-16 23:47 ` [Bug c++/96227] " pinskia at gcc dot gnu.org
  2021-07-16 23:51 ` pinskia at gcc dot gnu.org
@ 2021-07-17  7:36 ` jakub at gcc dot gnu.org
  2022-12-19 21:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-07-17  7:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think so, the evaluation order when invoking operator, not through the x, y
syntax is like for any other function call, the arguments evaluation is
indeterminately sequenced.
See https://en.cppreference.com/w/cpp/language/eval_order

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

* [Bug c++/96227] Comma operation sequencing issue
  2020-07-16 21:47 [Bug c++/96227] New: Comma operation sequencing issue matt at godbolt dot org
                   ` (2 preceding siblings ...)
  2021-07-17  7:36 ` jakub at gcc dot gnu.org
@ 2022-12-19 21:43 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-19 21:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |8.5
         Resolution|---                         |FIXED
             Status|WAITING                     |RESOLVED

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

end of thread, other threads:[~2022-12-19 21:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 21:47 [Bug c++/96227] New: Comma operation sequencing issue matt at godbolt dot org
2021-07-16 23:47 ` [Bug c++/96227] " pinskia at gcc dot gnu.org
2021-07-16 23:51 ` pinskia at gcc dot gnu.org
2021-07-17  7:36 ` jakub at gcc dot gnu.org
2022-12-19 21:43 ` 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).