Different results between gcc and clang when compiling a rather simple c++11 program

Update: Thanks to Faisal Vali and Richard Smith, this bug has been corrected in Clang ToT; see the test file introduced by the commit. According to ยง8.5.1 [dcl.init.aggr] it appears that Clang is wrong: 11/ Braces can be elided in an initializer-list as follows. If the initializer-list begins with a left brace, then the succeeding …

Read more

Does initialization entail lvalue-to-rvalue conversion? Is `int x = x;` UB?

UPDATE: Following the discussion in the comments, I added some more evidence at the end of this answer. Disclaimer: I admit this answer is rather speculative. The current formulation of the C++11 Standard, on the other hand, does not seem to allow for a more formal answer. In the context of this Q&A, it has …

Read more

Make custom type “tie-able” (compatible with std::tie)

Why the current attempts fail std::tie(a, b) produces a std::tuple<int&, string&>. This type is not related to std::tuple<int, string> etc. std::tuple<T…>s have several assignment-operators: A default assignment-operator, that takes a std::tuple<T…> A tuple-converting assignment-operator template with a type parameter pack U…, that takes a std::tuple<U…> A pair-converting assignment-operator template with two type parameters U1, U2, …

Read more

How to use the boost library (including shared_ptr) with the Android NDK and STLport

It turned out that this approach does not entirely work when compiling a debuggable library. The release library is compiled with -O2 which optimizes out some infelicities, but the debug library is done with -O0 which reveals some additional problems. Furthermore, I wasn’t too happy about having to edit the boost files. So with some …

Read more

Is stateful metaprogramming ill-formed (yet)?

This is CWG active issue 2118: Defining a friend function in a template, then referencing that function later provides a means of capturing and retrieving metaprogramming state. This technique is arcane and should be made ill-formed. Notes from the May, 2015 meeting: CWG agreed that such techniques should be ill-formed, although the mechanism for prohibiting …

Read more

reinterpret_cast creating a trivially default-constructible object

There is no X object, living or otherwise, so pretending that there is one results in undefined behavior. [intro.object]/1 spells out exhaustively when objects are created: An object is created by a definition ([basic.def]), by a new-expression ([expr.new]), when implicitly changing the active member of a union ([class.union]), or when a temporary object is created …

Read more