Patchwork [v3] is_literal_type tests

login
register
mail settings
Submitter Benjamin Kosnik
Date Nov. 5, 2010, 10:50 p.m.
Message ID <20101105155006.103e19a0@shotwell>
Download mbox | patch
Permalink /patch/70307/
State New
Headers show

Comments

Benjamin Kosnik - Nov. 5, 2010, 10:50 p.m.
Adjust doxygen files for the tr1_impl removal.

Adds test for integral_constant. 

Adds tests for std::is_literal_type. 

Of note on this is the divergence with is_literal_type and 3.9p10. As
per:

struct NLType // not literal type?
{
  int _M_i;
  
  NLType() : _M_i(0) { }
  
  constexpr NLType(int __i) : _M_i(__i) { }
  
  NLType(const NLType& __other) : _M_i(__other._M_i) { }
};

This is a literal_type as per std::is_literal_type, even with
non-trivial default constructor and copy constructors
that via 3.9p10 would be expected to fail. 

tested x86_64/linux

-benjamin
Paolo Carlini - Nov. 6, 2010, 12:19 a.m.
On 11/05/2010 11:50 PM, Benjamin Kosnik wrote:
> Of note on this is the divergence with is_literal_type and 3.9p10. As
> per:
>
> struct NLType // not literal type?
> {
>   int _M_i;
>   
>   NLType() : _M_i(0) { }
>   
>   constexpr NLType(int __i) : _M_i(__i) { }
>   
>   NLType(const NLType& __other) : _M_i(__other._M_i) { }
> };
>
> This is a literal_type as per std::is_literal_type, even with
> non-trivial default constructor and copy constructors
> that via 3.9p10 would be expected to fail. 
>   
Interesting indeed. Thus, does this imply something is wrong with
__is_literal_type? Is this a known issue?

Thanks,
Paolo.
Jason Merrill - Nov. 6, 2010, 1:46 a.m.
On 11/05/2010 08:19 PM, Paolo Carlini wrote:
> On 11/05/2010 11:50 PM, Benjamin Kosnik wrote:
>> Of note on this is the divergence with is_literal_type and 3.9p10. As
>> per:
>>
>> struct NLType // not literal type?
>> {
>>    int _M_i;
>>
>>    NLType() : _M_i(0) { }
>>
>>    constexpr NLType(int __i) : _M_i(__i) { }
>>
>>    NLType(const NLType&  __other) : _M_i(__other._M_i) { }
>> };
>>
>> This is a literal_type as per std::is_literal_type, even with
>> non-trivial default constructor and copy constructors
>> that via 3.9p10 would be expected to fail.
>>
> Interesting indeed. Thus, does this imply something is wrong with
> __is_literal_type? Is this a known issue?

I deliberately dropped the constraint on copy constructors, and have 
proposed removing it from the standard.

Jason
Benjamin Kosnik - Nov. 6, 2010, 5:45 a.m.
> I deliberately dropped the constraint on copy constructors, and have 
> proposed removing it from the standard.

Yeah. And default constructors too, right? I figured this was
deliberate, and then went looking for the proposed wording. It's not
part of 

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3142.html

? Pointer appreciated.

-benjamin

Patch


2010-11-05  Benjamin Kosnik  <bkoz@redhat.com>

	* doc/doxygen/user.cfg.in: Remove tr1_impl headers.

	* testsuite/tr1/4_metaprogramming/integral_constant/requirements/
	constexpr_data.cc: New.

	* testsuite/util/testsuite_tr1.h (LType, LTypeDerived, NLType): New.
	* testsuite/20_util/is_literal_type/value.cc: New.
	* testsuite/20_util/is_literal_type/requirements/typedefs.cc: Name.
	* testsuite/20_util/is_literal_type/requirements/
	explicit_instantiation.cc: New.


Index: doc/doxygen/user.cfg.in
===================================================================
--- doc/doxygen/user.cfg.in	(revision 166379)
+++ doc/doxygen/user.cfg.in	(working copy)
@@ -586,6 +586,7 @@ 
                          @srcdir@/libsupc++/cxxabi.h \
                          @srcdir@/libsupc++/cxxabi-forced.h \
                          @srcdir@/libsupc++/exception \
+                         @srcdir@/libsupc++/exception_defines.h \
                          @srcdir@/libsupc++/exception_ptr.h \
                          @srcdir@/libsupc++/initializer_list \
                          @srcdir@/libsupc++/nested_exception.h \
@@ -665,6 +666,7 @@ 
                          include/backward/strstream \
                          include/debug/bitset \
                          include/debug/deque \
+                         include/debug/forward_list \
                          include/debug/list \
                          include/debug/map \
                          include/debug/set \
@@ -674,6 +676,7 @@ 
                          include/debug/vector \
                          include/profile/bitset \
                          include/profile/deque \
+                         include/profile/forward_list \
                          include/profile/list \
                          include/profile/map \
                          include/profile/set \
@@ -707,20 +710,6 @@ 
                          include/tr1/ctime \
                          include/tr1/cwchar \
                          include/tr1/cwctype \
-                         include/tr1_impl/array \
-                         include/tr1_impl/cctype \
-                         include/tr1_impl/cfenv \
-                         include/tr1_impl/cinttypes \
-                         include/tr1_impl/cmath \
-                         include/tr1_impl/complex \
-                         include/tr1_impl/cstdint \
-                         include/tr1_impl/cstdio \
-                         include/tr1_impl/cstdlib \
-                         include/tr1_impl/cwchar \
-                         include/tr1_impl/cwctype \
-                         include/tr1_impl/type_traits \
-                         include/tr1_impl/utility \
-                         include/tr1_impl \
                          include/decimal/decimal \
                          include/ \
                          include/@host_alias@/bits \
@@ -728,6 +717,7 @@ 
                          include/bits \
                          include/debug \
                          include/parallel \
+			 include/precompiled \
                          include/profile \
                          include/profile/impl \
                          include/ext \
Index: testsuite/tr1/4_metaprogramming/integral_constant/requirements/constexpr_data.cc
===================================================================
--- testsuite/tr1/4_metaprogramming/integral_constant/requirements/constexpr_data.cc	(revision 0)
+++ testsuite/tr1/4_metaprogramming/integral_constant/requirements/constexpr_data.cc	(revision 0)
@@ -0,0 +1,52 @@ 
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <testsuite_common_types.h>
+
+namespace __gnu_test
+{
+  struct constexpr_member_data
+  {
+    template<typename _Ttesttype>
+      void
+      operator()()
+      {
+	struct _Concept
+	{
+	  void __constraint()
+	  {
+	    constexpr auto v __attribute__((unused)) (_Ttesttype::value);
+	  }
+	};
+
+	_Concept c;
+	c.__constraint();
+      }
+  };
+}
+
+int main()
+{
+  __gnu_test::constexpr_member_data test;
+  test.operator()<std::integral_constant<unsigned short, 69>>();
+  test.operator()<std::integral_constant<bool, true>>();
+  return 0;
+}
Index: testsuite/util/testsuite_tr1.h
===================================================================
--- testsuite/util/testsuite_tr1.h	(revision 166379)
+++ testsuite/util/testsuite_tr1.h	(working copy)
@@ -57,7 +57,7 @@ 
   // For testing tr1/type_traits/extent, which has a second template
   // parameter.
   template<template<typename, unsigned> class Property,
-           typename Type, unsigned Uint>
+	   typename Type, unsigned Uint>
     bool
     test_property(typename Property<Type, Uint>::value_type value)
     {
@@ -80,7 +80,7 @@ 
 #endif
 
   template<template<typename, typename> class Relationship,
-           typename Type1, typename Type2>
+	   typename Type1, typename Type2>
     bool
     test_relationship(bool value)
     {
@@ -188,6 +188,33 @@ 
     int j;
   };
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  struct LType // literal type
+  {
+    int _M_i;
+
+    constexpr LType(int __i) : _M_i(__i) { }
+  };
+
+  struct LTypeDerived : public LType
+  {
+    constexpr LTypeDerived(int __i) : LType(__i) { }
+  };
+
+  struct NLType // not literal type
+  {
+    int _M_i;
+
+    NLType() : _M_i(0) { }
+
+    constexpr NLType(int __i) : _M_i(__i) { }
+
+    NLType(const NLType& __other) : _M_i(__other._M_i) { }
+
+    ~NLType() { _M_i = 0; }
+  };
+#endif
+
   int truncate_float(float x) { return (int)x; }
   long truncate_double(double x) { return (long)x; }
 
@@ -251,7 +278,7 @@ 
 
   // For use in 8_c_compatibility.
   template<typename R, typename T>
-    typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value, 
+    typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
 				    bool>::__type
     check_ret_type(T)
     { return true; }
Index: testsuite/20_util/is_literal_type/value.cc
===================================================================
--- testsuite/20_util/is_literal_type/value.cc	(revision 0)
+++ testsuite/20_util/is_literal_type/value.cc	(revision 0)
@@ -0,0 +1,54 @@ 
+// { dg-options "-std=gnu++0x" }
+// 2010-03-23  Paolo Carlini  <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::is_literal_type;
+  using namespace __gnu_test;
+
+  VERIFY( (test_category<is_literal_type, int>(true)) );
+  VERIFY( (test_category<is_literal_type, unsigned char>(true)) );
+
+  VERIFY( (test_category<is_literal_type, TType>(true)) );
+  VERIFY( (test_category<is_literal_type, PODType>(true)) );
+
+  VERIFY( (test_category<is_literal_type, NType>(false)) );
+  VERIFY( (test_category<is_literal_type, SLType>(false)) );
+
+  VERIFY( (test_category<is_literal_type, LType>(true)) );
+  VERIFY( (test_category<is_literal_type, LType[5]>(true)) );
+
+  VERIFY( (test_category<is_literal_type, NLType>(false)) );
+  VERIFY( (test_category<is_literal_type, NLType[5]>(false)) );
+
+  VERIFY( (test_category<is_literal_type, LTypeDerived>(true)) );
+  VERIFY( (test_category<is_literal_type, LTypeDerived[5]>(true)) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/20_util/is_literal_type/requirements/typedefs.cc
===================================================================
--- testsuite/20_util/is_literal_type/requirements/typedefs.cc	(revision 0)
+++ testsuite/20_util/is_literal_type/requirements/typedefs.cc	(revision 0)
@@ -0,0 +1,36 @@ 
+// { dg-options "-std=gnu++0x" }
+// 2010-02-21  Paolo Carlini  <paolo.carlini@oracle.com>
+//
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+//
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+// { dg-do compile }
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::is_literal_type<int>                test_type;
+  typedef test_type::value_type               value_type;
+  typedef test_type::type                     type;
+  typedef test_type::type::value_type         type_value_type;
+  typedef test_type::type::type               type_type;
+}
Index: testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc
===================================================================
--- testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc	(revision 0)
+++ testsuite/20_util/is_literal_type/requirements/explicit_instantiation.cc	(revision 0)
@@ -0,0 +1,30 @@ 
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+// 2010-02-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+  typedef short test_type;
+  template struct is_literal_type<test_type>;
+}