LWG Issue 2141: common type

Marshall Clow mclow.lists at gmail.com
Mon Oct 7 15:53:52 PDT 2013


On Oct 7, 2013, at 1:26 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Sun, Oct 6, 2013 at 9:37 AM, Marshall Clow <mclow.lists at gmail.com> wrote:
> Ref: http://cplusplus.github.io/LWG/lwg-defects.html#2141
> 
> Fix common_type to match the suggested implementation in the standard.
> Add tests to make sure it (now) does what it should.
> 
> Also, a drive by fix on the tests for is_trivially_copyable. Clang recently fixed a bug in the intrinsic that libc++ uses for this type_trait, and this exposed an error in the test suite.
> 
> Note that most of the change in <type_traits> is from hoisting the definition of std::decay from the end of the file to somewhere closer to the front.
> That's just a movement of source code - there are no changes to decay.
> 
> You don't seem to have any test coverage outside C++1y mode. Could you move the tests out of the _LIBCPP_STD_VER > 11 block and switch them from common_type_t to common_type<...>::type ?


Was this what you had in mind?

Index: test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp
===================================================================
--- test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp	(revision 192102)
+++ test/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp	(working copy)
@@ -18,10 +18,24 @@
     static_assert((std::is_same<std::common_type<int>::type, int>::value), "");
     static_assert((std::is_same<std::common_type<char>::type, char>::value), "");
 #if _LIBCPP_STD_VER > 11
-    static_assert((std::is_same<std::common_type_t<int>, int>::value), "");
+    static_assert((std::is_same<std::common_type_t<int>,   int>::value), "");
     static_assert((std::is_same<std::common_type_t<char>, char>::value), "");
 #endif
 
+    static_assert((std::is_same<std::common_type<               int>::type, int>::value), "");
+    static_assert((std::is_same<std::common_type<const          int>::type, int>::value), "");
+    static_assert((std::is_same<std::common_type<      volatile int>::type, int>::value), "");
+    static_assert((std::is_same<std::common_type<const volatile int>::type, int>::value), "");
+
+    static_assert((std::is_same<std::common_type<int,           int>::type, int>::value), "");
+    static_assert((std::is_same<std::common_type<int,     const int>::type, int>::value), "");
+    
+    static_assert((std::is_same<std::common_type<long,       const int>::type, long>::value), "");
+    static_assert((std::is_same<std::common_type<const long,       int>::type, long>::value), "");
+    static_assert((std::is_same<std::common_type<long,    volatile int>::type, long>::value), "");
+    static_assert((std::is_same<std::common_type<volatile long,    int>::type, long>::value), "");
+    static_assert((std::is_same<std::common_type<const long, const int>::type, long>::value), "");
+
     static_assert((std::is_same<std::common_type<double, char>::type, double>::value), "");
     static_assert((std::is_same<std::common_type<short, char>::type, int>::value), "");
 #if _LIBCPP_STD_VER > 11

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists at gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131007/4814343c/attachment.html>


More information about the cfe-commits mailing list