-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"rejects-valid
Description
Though std::complex<>::operator+
(and others) are constexpr
in C++20, the code below fails to compile.
#include <complex>
constexpr std::complex<double> x{1, 2};
constexpr std::complex<double> y = x + x;
I am using libstdc++ and note that the constexpr
declarations are in place there, and also that g++ does compile it. I am on Ubuntu 21.10. Clang trunk also fails. The error message is below. I suspect it relates to constexpr
support for __complex__
.
$ clang++ -c -std=c++20 complex-constexpr.cpp
complex-constexpr.cpp:4:32: error: constexpr variable 'y' must be initialized by a constant expression
constexpr std::complex<double> y = x + x;
^ ~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/complex:1336:13: note: subexpression not valid in a constant expression
_M_value += __z.__rep();
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/complex:335:11: note: in call to '&__r->operator+=(x)'
__r += __y;
^
complex-constexpr.cpp:4:38: note: in call to 'operator+(x, x)'
constexpr std::complex<double> y = x + x;
^
1 error generated.
AlexVermette-Eaton and mpuszAlexVermette-Eaton
Metadata
Metadata
Assignees
Labels
c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"rejects-valid
Type
Projects
Status
No status