Can I use a constexpr value in a lambda without capturing it?

Should this be considered a bug in clang 3.8? Yep. A capture is only needed if [expr.prim.lambda]/12 mandates so: Note in particular the highlighted example. f(x) does not necessitate x to be captured, because it isn’t odr-used (overload resolution selects the overload with the object parameter). The same argumentation applies to your code – [basic.def.odr]/3: … Read more

Why does adding const turn a forwarding reference into an rvalue reference?

The official name is not universal reference, but forwarding reference. The Standard states that only rvalue references to cv-unqualified template parameters fall in this category: 14.8.2.1 Deducing template arguments from a function call [temp.deduct.call] 3 If P is a cv-qualified type, the top level cv-qualifiers of P’s type are ignored for type deduction. If P … Read more

Pointer to class member as a template parameter

In c++17, with the addition of auto in template arguments (P0127), I think you can now do: template<auto value> struct MyStruct {}; template<typename Class, typename Result, Result Class::* value> struct MyStruct<value> { // add members using Class, Result, and value here using containing_type = Class; }; typename MyStruct<&Something::theotherthing>::containing_type x = Something();

Can returning a local variable by value in C++11/14 result in the return value being constructed by rvalue when no copy/move is involved?

The rule for this situation changed between 2011 and 2014. The compiler should now treat localB as an rvalue. The applicable rule for return statements is found in §12.8 [class.copy]/p32, which reads in C++14 (quoting N3936, emphasis mine): When the criteria for elision of a copy/move operation are met, but not for an exception-declaration, and … Read more

Why aren’t std::algorithms constexpr and which could be?

It could be constexpr, but cannot be evaluated as a constant expression, since in this case, for example for compile-time find it is required that: begin/end should be constexpr, the * operator of the iterator should be constexpr, operator == should be constexpr, operator != for the iterator should be constexpr, operator ++ for the … Read more

Why is non-const std::array::operator[] not constexpr?

Ok, it is indeed an oversight in the standard. There even exists a proposal to fix this: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0107r0.pdf [N3598] removed the implicit marking of constexpr member functions as const. However, the member functions of std::array were not revisited after this change, leading to a surprising lack of support for constexpr in std::array’s interface. This paper … Read more

std::unique_ptr of base class holding reference of derived class does not show warning in gcc compiler while naked pointer shows it. Why?

Well, first of all, deleting a derived object through a base pointer when the base class does not have a virtual destructor is undefined behavior. Compilers are not required to diagnose undefined behavior… That being said, the reason why this warning does not appear when using std::unique_ptr is most likely due to the fact that … Read more