https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99535
Bug ID: 99535
Summary: g++ rejects valid code in constexpr copy ctor and
volatile submember
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Darrell.Wright at gmail dot com
Target Milestone: ---
The following code produces an error
struct Thing0 {
volatile int a;
constexpr Thing0( int v ): a{v} {}
constexpr Thing0(Thing0 const& other) : a(other.a) {}
constexpr Thing0& operator=(Thing0 const& rhs) {
a = rhs.a;
return *this;
}
~Thing0() = default;
};
Thing0 func0() { return Thing0{5}; }
<source>: In copy constructor 'constexpr Thing0::Thing0(const Thing0&)':
<source>:7:51: error: lvalue-to-rvalue conversion of a volatile lvalue
'other.Thing0::a' with type 'const volatile int'
7 | constexpr Thing0(Thing0 const& other) : a(other.a) {}
| ~~~~~~^
<source>: In member function 'constexpr Thing0& Thing0::operator=(const
Thing0&)':
<source>:9:13: error: lvalue-to-rvalue conversion of a volatile lvalue
'rhs.Thing0::a' with type 'const volatile int'
9 | a = rhs.a;
| ~~~~^
The code should be accepted and is when the special methods are not constexpr.