Created attachment 22413
Code as described.
The C++11 code below (also attached) will fail to compile:
struct Bar {};
struct Foo { Bar t; };
template <typename T>
constexpr T jam(T &&a) { return a; }
void test()
{
Foo y;
constexpr Foo x = jam(y);
}
Changing the types of x and y from Foo to Bar will remove the error. GCC
snapshot 17th August 2019 produces no error. The error message follows:
constexpr_rvalue.cpp:10:17: error: constexpr variable 'x' must be initialized
by a constant expression
constexpr Foo x = jam(y);
^ ~~~~~~
constexpr_rvalue.cpp:10:21: note: read of non-constexpr variable 'y' is not
allowed in a constant expression
constexpr Foo x = jam(y);
^
constexpr_rvalue.cpp:10:21: note: in call to 'Foo(y)'
constexpr_rvalue.cpp:9:7: note: declared here
Foo y;
^
1 error generated.
constexpr_rvalue.cpp
(152 bytes, text/x-c++src)