In the C ++ 14 standard (ISO / IEC 14882: 2014) in the section of paragraph 2 of section 5.19 (primary focus) the word " non-mutable " was added :
The conditional expression e is an expression of the basic constant if the estimate e, following the rules of the abstract machine (1.9), does not evaluate one of the following expressions:
- [...]
- lvalue-to-rvalue conversion (4.1) if it does not apply to
- [...]
- unchangeable value glvalue, which relates to a nonvolatile object determined via constexpr, or relates to a sub-object is not a variable of the object or
Therefore this code is incorrect in C ++ 14:
class A {
public:
mutable int x;
};
int main(){
constexpr A a = {1};
constexpr int y = a.x;
return 0;
}
However, is this correct in C ++ 11?
(CD3) 1405, :
. , - constexpr , , .
, , ++ 11. , Clang GCC -std = ++ 11, , . ++ 14, ++ 11.
- , ++ 11?
. (CD3) 1428.