[LLVMbugs] [Bug 22135] New: std::common_type<void, void> fails to compile

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jan 8 13:48:57 PST 2015


            Bug ID: 22135
           Summary: std::common_type<void, void> fails to compile
           Product: libc++
           Version: 3.4
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pip88nl at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

>From the description of std::common_type in the draft N4296, paragraph

The member typedef type shall be defined as set out below. All types in the
parameter pack T shall be complete or (possibly cv) void.

Further down, it specifies the implementation of common_type as follows:

— If sizeof...(T) is greater than one, let T1, T2, and R, respectively, denote
the first, second, and (pack of) remaining types comprising T. [ Note:
sizeof...(R) may be zero. — end note ] Let C denote the type, if any, of an
unevaluated conditional expression (5.16) whose first operand is an arbitrary
value of type bool, whose second operand is an xvalue of type T1, and whose
third operand is an xvalue of type T2. If there is such a type C, the member
typedef type shall denote the same type, if any, as common_type_t<C,R...>.

The problem here is that expression of type void are never xvalues, since there
is no way to create (rvalue) references to void. This is a defect in the
standard draft not present in the C++11 standard (where the implementation is
defined in terms of declval<T>()).

I suggest specialising the libc++ implementation such that argument packs
containing only void cause the type defined within common_type to be void.

My workaround is this:

template<typename ...Types>
struct common_type;

template<typename Type1, typename Type2, typename ...Types>
struct common_type<Type1, Type2, Types...>
  : common_type<typename common_type<Type1, Type2>::type, Types...>
{ };

template<typename Type1, typename Type2>
struct common_type<Type1, Type2>
  : std::common_type<Type1, Type2>
{ };

struct common_type<void, void>
{ typedef void type; };

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150108/3306cbfa/attachment.html>

More information about the llvm-bugs mailing list