Open llvmbot opened 6 years ago
This code is accepted by all of clang post 18 trunk(d9a9872ec4760762fdc467ef283cea302a3742e5), gcc13.2, msvc 19.38, and EDG 6.6 https://godbolt.org/z/qP4T96hef code
constexpr int f(int x) {return x++ + x++;}
int main() {
constexpr int x = 2;
constexpr int y = f(x);
return y;
}
clang has a warning (without any extra flags specified) the rest have no warnings (without specifying any flags)
clang warning
<source>:1:33: warning: multiple unsequenced modifications to 'x' [-Wunsequenced]
1 | constexpr int f(int x) {return x++ + x++;}
| ^ ~~
1 warning generated.
Compiler returned: 0
@llvm/issue-subscribers-clang-frontend
Author: None (llvmbot)
This is CWG2192.
Extended Description
Given
clang does not consider the declaration of y ill-formed but I believe it should.
is undefined behavior since we have unsequenced modifications to x. See [intro.execution]p10 http://eel.is/c++draft/intro.execution#10 and this should be ill-formed in a context requiring a constant expression since undefined behavior is ill-formed in a constant expression see [expr.cons]p2.6 http://eel.is/c++draft/expr.const#2.6