This question already has an answer here:I cannot understand the purpose of marking the setter function as constexpr, that is allowed since C++14. My misunderstanding comes from the next situation: I declare a class with a constexpr c-tor, and I am about to use it in a constexpr context, by...
Why doesn't the following code compile?The compile command:The output:I'm using gcc6.4.The restrictions on what can be used in a constant expression are defined mostly as a list of negatives. There's a bunch of things you're not allowed to evaluate ([expr.const]/2 in C++14) and certain things that values have to result...
GCC9 already implements std::is_constant_evaluated. I played a little bit with it, and I realized it is somewhat tricky. Here’s my test:
Why does this code return a warning warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
In the following code (tested locally and on Wandbox):MSVC 15.8.5 fails to compile with:(all referring to the line containing constexpr)
Why is a constexpr function no evaluated at compile time but in runtime in the return statement of main function?
I have my own fixed-size array type I want to be constexpr constructible from an std::initializer_list without having to explicitly define the size template argument.
I was reviewing the interface for the C++-17 std::optional class template and noticed that the reset and assignment from nullopt are not marked as constexpr.
Consider a simple example:I would say it is a bug but both the latest [clang] and [gcc] accept the code so maybe I'm missing some relevant standard rule that makes the code valid?
The code doesn't compiled in clang, it produces the following diagnostic:MSVC crashed (according to godbolt) and gcc works fine. If a /= b is simply replaced by a = a / b then everybody accepts it. Why?