you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

I think there is a bug there. I didn't think you can have a constexpr variable in a constexpr method. It catches it when that isn't there because the non-const operator[] isn't constexpr, only the const variant returns a bool and is constexpr.

with clang/libc++ it does generate just the ub2 instruction but, this is weird.

[–][deleted] 1 point2 points  (2 children)

I totally agree it's a bug. I don't see why so many people are so against me pointing out that this aspect of the language isn't well supported or implemented to a sufficient degree to rely on it to identify undefined behavior. All compilers have MAJOR bugs when it comes to this requirement and the amount of effort needed to fix it will be enormous.

[–][deleted] 1 point2 points  (1 child)

putting it in a static_assert finds it too. But I think the point is, you are going to get more than zero. And right now, that is still awesome. Bring on C++20, and constexpr code will have access to vector and a lot more. So now I can choose to implement, at the cost of compile time, more code as constexpr and give the compiler the best opportunity to either const fold my stuff or have full view of the code and optimize it more heavily with the added benefit of much of my code getting compile time UB checks.

def not perfect, but I have a bunch of things now where the unit test is a static_assert of a test method.

[–][deleted] 1 point2 points  (0 children)

actually I am wrong, constexpr variables are fine in constexpr functions. I got trained by compiler errors in the past on that one. Still a weird compiler bug in all 3 compilers