[Bug c++/96227] New: Comma operation sequencing issue
matt at godbolt dot org
gcc-bugzilla@gcc.gnu.org
Thu Jul 16 21:47:03 GMT 2020
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
More information about the Gcc-bugs
mailing list