diff mbox

[v3] libstdc++/46718

Message ID 4CF4F439.6080301@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 30, 2010, 12:55 p.m. UTC
Hi,

this straightforward patch makes sure that std::is_scalar is true for
std::nullptr_t. I'm adding in CC Jason just in case he believes
something should be done at the C++ front-end level too (I don't think so).

Tested x86_64-linux multilib, committed.

Paolo.

//////////////////////////////
2010-11-30  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/46718
	* include/std/type_traits (__is_nullptr_t): Add.
	(is_scalar): Use the latter.
	* testsuite/20_util/is_scalar/value.cc: New.
	* testsuite/20_util/is_scalar/requirements/typedefs.cc: Likewise.
	* testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
	Adjust dg-error line numbers.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/20_util/declval/requirements/1_neg.cc: Likewise.

Comments

Jason Merrill Nov. 30, 2010, 10:07 p.m. UTC | #1
On 11/30/2010 07:55 AM, Paolo Carlini wrote:
> this straightforward patch makes sure that std::is_scalar is true for
> std::nullptr_t. I'm adding in CC Jason just in case he believes
> something should be done at the C++ front-end level too (I don't think so).

I don't think so, either; this looks right to me.

Jason
diff mbox

Patch

Index: include/std/type_traits
===================================================================
--- include/std/type_traits	(revision 167292)
+++ include/std/type_traits	(working copy)
@@ -250,6 +250,18 @@ 
     struct is_function<_Res(_ArgTypes......) const volatile>
     : public true_type { };
 
+  template<typename>
+    struct __is_nullptr_t_helper
+    : public false_type { };
+  _DEFINE_SPEC(0, __is_nullptr_t_helper, std::nullptr_t, true)
+
+  // __is_nullptr_t (extension).
+  template<typename _Tp>
+    struct __is_nullptr_t
+    : public integral_constant<bool, (__is_nullptr_t_helper<typename
+				      remove_cv<_Tp>::type>::value)>
+    { };
+
   // composite type traits.
   
   /// is_arithmetic
@@ -284,7 +296,8 @@ 
     : public integral_constant<bool, (is_arithmetic<_Tp>::value
 				      || is_enum<_Tp>::value
 				      || is_pointer<_Tp>::value
-				      || is_member_pointer<_Tp>::value)>
+				      || is_member_pointer<_Tp>::value
+				      || __is_nullptr_t<_Tp>::value)>
     { };
 
   /// is_compound
Index: testsuite/20_util/make_signed/requirements/typedefs_neg.cc
===================================================================
--- testsuite/20_util/make_signed/requirements/typedefs_neg.cc	(revision 167292)
+++ testsuite/20_util/make_signed/requirements/typedefs_neg.cc	(working copy)
@@ -48,5 +48,5 @@ 
 // { dg-error "instantiated from here" "" { target *-*-* } 40 }
 // { dg-error "instantiated from here" "" { target *-*-* } 42 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1082 }
-// { dg-error "declaration of" "" { target *-*-* } 1046 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1095 }
+// { dg-error "declaration of" "" { target *-*-* } 1059 }
Index: testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
===================================================================
--- testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc	(revision 167292)
+++ testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc	(working copy)
@@ -48,5 +48,5 @@ 
 // { dg-error "instantiated from here" "" { target *-*-* } 40 }
 // { dg-error "instantiated from here" "" { target *-*-* } 42 }
 
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1005 }
-// { dg-error "declaration of" "" { target *-*-* } 969 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1018 }
+// { dg-error "declaration of" "" { target *-*-* } 982 }
Index: testsuite/20_util/declval/requirements/1_neg.cc
===================================================================
--- testsuite/20_util/declval/requirements/1_neg.cc	(revision 167292)
+++ testsuite/20_util/declval/requirements/1_neg.cc	(working copy)
@@ -19,7 +19,7 @@ 
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "static assertion failed" "" { target *-*-* } 1119 }
+// { dg-error "static assertion failed" "" { target *-*-* } 1132 }
 
 #include <utility>
 
Index: testsuite/20_util/is_scalar/value.cc
===================================================================
--- testsuite/20_util/is_scalar/value.cc	(revision 0)
+++ testsuite/20_util/is_scalar/value.cc	(revision 0)
@@ -0,0 +1,48 @@ 
+// { dg-options "-std=gnu++0x" }
+// 2010-11-30  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_scalar;
+  using namespace __gnu_test;
+
+  VERIFY( (test_category<is_scalar, int>(true)) );
+  VERIFY( (test_category<is_scalar, float>(true)) );
+  VERIFY( (test_category<is_scalar, EnumType>(true)) );
+  VERIFY( (test_category<is_scalar, int*>(true)) );
+  VERIFY( (test_category<is_scalar, int(*)(int)>(true)) );
+  VERIFY( (test_category<is_scalar, int (ClassType::*)>(true)) );
+  VERIFY( (test_category<is_scalar, int (ClassType::*) (int)>(true)) );
+  VERIFY( (test_category<is_scalar, std::nullptr_t>(true)) );
+
+  // Sanity check.
+  VERIFY( (test_category<is_scalar, ClassType>(false)) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/20_util/is_scalar/requirements/typedefs.cc
===================================================================
--- testsuite/20_util/is_scalar/requirements/typedefs.cc	(revision 0)
+++ testsuite/20_util/is_scalar/requirements/typedefs.cc	(revision 0)
@@ -0,0 +1,36 @@ 
+// 2010-11-30  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 tr1/type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::is_scalar<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_scalar/requirements/explicit_instantiation.cc
===================================================================
--- testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc	(revision 0)
+++ testsuite/20_util/is_scalar/requirements/explicit_instantiation.cc	(revision 0)
@@ -0,0 +1,29 @@ 
+// { 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/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+  typedef short test_type;
+  template struct is_scalar<test_type>;
+}