cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p.
authorMagnus Fromreide <magfr@lysator.liu.se>
Sat, 5 Jun 2010 04:52:18 +0000 (06:52 +0200)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 5 Jun 2010 04:52:18 +0000 (00:52 -0400)
* cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p.
* typeck.c (build_ptrmemfunc): Likewise.

From-SVN: r160309

25 files changed:
gcc/cp/ChangeLog
gcc/cp/cvt.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nullptr01.C
gcc/testsuite/g++.dg/cpp0x/nullptr02.C
gcc/testsuite/g++.dg/cpp0x/nullptr03.C
gcc/testsuite/g++.dg/cpp0x/nullptr04.C
gcc/testsuite/g++.dg/cpp0x/nullptr05.C
gcc/testsuite/g++.dg/cpp0x/nullptr06.C
gcc/testsuite/g++.dg/cpp0x/nullptr07.C
gcc/testsuite/g++.dg/cpp0x/nullptr08.C
gcc/testsuite/g++.dg/cpp0x/nullptr09.C
gcc/testsuite/g++.dg/cpp0x/nullptr10.C
gcc/testsuite/g++.dg/cpp0x/nullptr11.C
gcc/testsuite/g++.dg/cpp0x/nullptr12.C
gcc/testsuite/g++.dg/cpp0x/nullptr13.C
gcc/testsuite/g++.dg/cpp0x/nullptr14.C
gcc/testsuite/g++.dg/cpp0x/nullptr15.C
gcc/testsuite/g++.dg/cpp0x/nullptr16.C
gcc/testsuite/g++.dg/cpp0x/nullptr17.C
gcc/testsuite/g++.dg/cpp0x/nullptr18.C
gcc/testsuite/g++.dg/cpp0x/nullptr20.C
gcc/testsuite/g++.dg/cpp0x/nullptr21.C
gcc/testsuite/g++.dg/cpp0x/nullptr22.C

index b0510792fcf72006a01c0a936c9523eb212d5f70..9c4ad0ae569a9e69fdeb155d402ea6d51d38dd02 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-04  Magnus Fromreide  <magfr@lysator.liu.se>
+
+       * cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p.
+       * typeck.c (build_ptrmemfunc): Likewise.
+
 2010-06-04  Jason Merrill  <jason@redhat.com>
 
        * typeck2.c (merge_exception_specifiers): Adjust merging of
index 71315b1f4fd40ad9a4d16b431026614db0c825e3..4aee15111ed9e7a1eb9e7a1a28ad35c47a05af04 100644 (file)
@@ -196,7 +196,7 @@ cp_convert_to_pointer (tree type, tree expr)
       return error_mark_node;
     }
 
-  if (integer_zerop (expr))
+  if (null_ptr_cst_p (expr))
     {
       if (TYPE_PTRMEMFUNC_P (type))
        return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
index 26ffe1cc416e732d960e531b8ade1df2471b7bca..53e84cf5a40544e74f6d334cbb69a919fc21a6e6 100644 (file)
@@ -7039,7 +7039,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p)
     }
 
   /* Handle null pointer to member function conversions.  */
-  if (integer_zerop (pfn))
+  if (null_ptr_cst_p (pfn))
     {
       pfn = build_c_cast (input_location, type, integer_zero_node);
       return build_ptrmemfunc1 (to_type,
index 0998820f7d0b4caee09ce459e7d919fa82c17a45..accf2e37deeab9d2396d5848f0d7017a339d2e15 100644 (file)
@@ -1,3 +1,28 @@
+2010-06-04  Magnus Fromreide  <magfr@lysator.liu.se>
+
+       * g++.dg/cpp0x/nullptr01.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr02.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr03.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr04.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr05.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr06.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr07.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr08.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr09.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr10.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr11.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr12.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr13.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr14.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr15.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr16.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr17.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr18.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr19.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr20.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr21.C: Test nullptr_t variable.
+       * g++.dg/cpp0x/nullptr22.C: Test nullptr_t variable.
+
 2010-06-04  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/cpp0x/noexcept06.C: New.
index 8de877bab50f8e8763d40c9d9f1439a21bb388cf..de3860c9ea417ac3dcfaa585bb59640d7c9f1da6 100644 (file)
@@ -6,3 +6,5 @@
 char* const cp1 = nullptr;
 char* const cp2 = __null;
 char* const cp3 = 0;
+decltype(nullptr) mynull = 0;
+char* const cp4 = mynull;
index 2272152cf730313b5049dade47853bd78cd157f4..80977cb2f00e41670a227731bddf77c50c97dd25 100644 (file)
@@ -8,3 +8,9 @@ typedef decltype(nullptr) nullptr_t;
 const nullptr_t np1 = nullptr;
 const nullptr_t np2 = __null;
 const nullptr_t np3 = 0;
+const nullptr_t np4 = np1;
+const nullptr_t np5 = np2;
+const nullptr_t np6 = np3;
+const nullptr_t np7 = np4;
+const nullptr_t np8 = np5;
+const nullptr_t np9 = np6;
index 1c9e521bd889e4015bfdddc73c71785e8affc079..b6df89637407942895767a6c3f5cf05c8efe7a58 100644 (file)
@@ -3,4 +3,7 @@
 
 // Test assignment to int
 
-const int n = nullptr;     // { dg-error "cannot convert " }
+const int n1 = nullptr;     // { dg-error "cannot convert " }
+decltype(nullptr) mynull = 0;
+const int n2 = mynull;      // { dg-error "cannot convert " }
+
index 28e37156f8cd30d0e20e4d50544677db8f0d85c7..6e1d1256c5783e5505338ebcdef51b5eb3092d37 100644 (file)
@@ -11,3 +11,9 @@ const int n4 = static_cast<const int>(nullptr); // { dg-error "invalid static_ca
 const short int n5 = reinterpret_cast<short int>(nullptr); // { dg-error "loses precision" }
 const ssize_t n6 = reinterpret_cast<ssize_t>(nullptr);
 const ssize_t n7 = (ssize_t)nullptr;
+
+decltype(nullptr) mynull = 0;
+const int n8 = static_cast<const int>(mynull); // { dg-error "invalid static_cast " }
+const short int n9 = reinterpret_cast<short int>(mynull); // { dg-error "loses precision" }
+const ssize_t n10 = reinterpret_cast<ssize_t>(mynull);
+const ssize_t n11 = (ssize_t)mynull;
index 7c3f8b7093df96290a78ddfbe48fa9388bcdea2a..22a8b51c1c7d115e833c3f7b52b8f76715844958 100644 (file)
@@ -10,3 +10,5 @@ typedef void (F::*pmf)();
 const pmf pmf1 = nullptr;
 const pmf pmf2 = __null;
 const pmf pmf3 = 0;
+decltype(nullptr) mynull = 0;
+const pmf pmf4 = mynull;
index 5dea1fbf171eef4b9fe77811dc5b0e54d6d97c4c..c50bb9bc1132ac1965a4ac819a261d1a02352517 100644 (file)
@@ -10,4 +10,6 @@ char* const cp1 = nullptr;
 void fun()
 {
   assert_true(cp1 == nullptr);
+  decltype(nullptr) mynull = 0;
+  assert_true(cp1 == mynull);
 }
index cebed8862dfdff07ca54de13a8f3d5998c7d1515..64d442be33115e16c219699af8e453c9c10f37ab 100644 (file)
@@ -9,4 +9,7 @@ void fun()
   if( n == nullptr ); // { dg-error "invalid operands of types " }
   const int m = 1;
   if( m == nullptr ); // { dg-error "invalid operands of types " }
+  decltype(nullptr) mynull = 0;
+  if( n == mynull ); // { dg-error "invalid operands of types " }
+  if( m == mynull ); // { dg-error "invalid operands of types " }
 }
index d7d9169f5a142cc3be8185cdc209c49192cf9f54..1e5db278ddf879da5bc7223f7c47fa3d083fc931 100644 (file)
@@ -8,4 +8,6 @@
 void fun()
 {
   assert_true(nullptr ? false : true);
+  decltype(nullptr) mynull = 0;
+  assert_true(mynull ? false : true);
 }
index a42821cbfa6b00dddad1891732362ff446ac1c32..b35a3c3207d1f311c09e8a01435b3fc0e817e5d1 100644 (file)
@@ -6,4 +6,6 @@
 void fun()
 {
   if( nullptr == 0 );
+  decltype(nullptr) mynull = 0;
+  if( mynull == 0 );
 }
index cd131864a336cced13d3bb87995e0a715c3792d8..fa32267ec028b563c937316da5258ef24a4b8673 100644 (file)
@@ -7,4 +7,8 @@ void fun()
 {
   nullptr = 0;         // { dg-error "lvalue required as left operand" }
   nullptr + 2;         // { dg-error "invalid operands of types " }
+  decltype(nullptr) mynull = 0;
+  mynull = 1;          // { dg-error "cannot convert" }
+  mynull = 0;
+  mynull + 2;          // { dg-error "invalid operands of types " }
 }
index 85402a1a2a379252ce4f0ae5717a39536effc147..5907816a847d51d8e13f67d845cb69b45c0dd834 100644 (file)
@@ -14,4 +14,27 @@ void fun()
   assert_false(nullptr > nullptr);
   assert_true(nullptr <= nullptr);
   assert_true(nullptr >= nullptr);
+
+  decltype(nullptr) mynull = 0;
+
+  assert_true(mynull == nullptr);
+  assert_false(mynull != nullptr);
+  assert_false(mynull < nullptr);
+  assert_false(mynull > nullptr);
+  assert_true(mynull <= nullptr);
+  assert_true(mynull >= nullptr);
+
+  assert_true(nullptr == mynull);
+  assert_false(nullptr != mynull);
+  assert_false(nullptr < mynull);
+  assert_false(nullptr > mynull);
+  assert_true(nullptr <= mynull);
+  assert_true(nullptr >= mynull);
+
+  assert_true(mynull == mynull);
+  assert_false(mynull != mynull);
+  assert_false(mynull < mynull);
+  assert_false(mynull > mynull);
+  assert_true(mynull <= mynull);
+  assert_true(mynull >= mynull);
 }
index f68652c999e6024f8704ccf9321b11cc11e58978..1713259f103626a89a55dfae773475bce4a686d7 100644 (file)
@@ -4,3 +4,5 @@
 // Test sizeof
 
 static_assert(sizeof(nullptr) == sizeof(void*), "sizeof(nullptr) is wrong");
+const decltype(nullptr) mynull = 0;
+static_assert(sizeof(mynull) == sizeof(void*), "sizeof(nullptr) is wrong");
index 633e971feca30c9b30269f73e83f600ebe2a3288..a9377584c56a2b3916b9e21cee919221056e0276 100644 (file)
@@ -5,7 +5,12 @@
 
 #include <typeinfo>
 
+#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
+
 void fun()
 {
   typeid(nullptr);
+  const decltype(nullptr) mynull = 0;
+  typeid(mynull);
+  assert_true(typeid(nullptr) == typeid(mynull));
 }
index 0493bcca0067f48b3eee43a71c3d7eb7f5dc2bc1..4c4627b541b0a0ddc660ddba42ba72d2ae043ae5 100644 (file)
@@ -20,4 +20,6 @@ void test_f()
   //
   type_equal<char*>(f(nullptr));
   type_equal<int>(f(0));
+  decltype(nullptr) mynull = 0;
+  type_equal<char*>(f(mynull));
 }
index abb45f4e9374568c48e36e03cd3c11acab3b4dfd..67d9d4a23117fa1e159deca4c673d00c9374820a 100644 (file)
@@ -18,4 +18,7 @@ void test_g()
   //
   g(nullptr);               // { dg-error "no matching function for call to " }
   type_equal<float*>(g((float*)nullptr));
+  decltype(nullptr) mynull = 0;
+  g(mynull);                // { dg-error "no matching function for call to " }
+  type_equal<float*>(g((float*)mynull));
 }
index 7561b21cfe3628c412b90ca4b700ea28fb33767a..0ec0b6a12b6fe02539ae80f46ecd11c7abae5089 100644 (file)
@@ -19,4 +19,7 @@ void test_h()
   type_equal<int>(h(0));
   type_equal<nullptr_t>(h(nullptr));
   type_equal<float*>(h((float*)nullptr));
+  nullptr_t mynull = 0;
+  type_equal<nullptr_t>(h(mynull));
+  type_equal<float*>(h((float*)mynull));
 }
index acedbae3787ef0e280bef01fbfef65a0a51a77fb..2e580557bc3a3c8f0c52a29a58bc7522fcf4eefd 100644 (file)
@@ -18,4 +18,6 @@ void test_i()
 {
   // Overload to bool, not int
   type_equal<bool>(i(nullptr));
+  decltype(nullptr) mynull = 0;
+  type_equal<bool>(i(mynull));
 }
index 192b646efb451f470502b81d5c196bd8ea627584..b8fa38c718d355df7e971c19f6bc55a3ab17ac14 100644 (file)
@@ -16,4 +16,6 @@ bool j(  bool );
 void test_j()
 {
   type_equal<char*>(j(nullptr));
+  decltype(nullptr) mynull = 0;
+  type_equal<char*>(j(mynull));
 }
index a959b00786f3af60c21914e4ef9c6d48b0d3648c..3e58406770dafc9d8881eca9893726b48ebffafa 100644 (file)
@@ -10,8 +10,11 @@ int main()
 {
   char buf1[64];
   char buf2[64];
+  char buf3[64];
 
   std::sprintf(buf1, "%p", (void*)0);
   std::sprintf(buf2, "%p", nullptr);
-  return std::strcmp(buf1, buf2) != 0;
+  decltype(nullptr) mynull = 0;
+  std::sprintf(buf3, "%p", nullptr);
+  return std::strcmp(buf1, buf2) != 0 || std::strcmp(buf1, buf3) != 0;
 }
index 84c34dd1e0a19c646531301e1bff955eca4d74d5..c30cb3c8b6de0880e5274d399e63f4960cdc32f8 100644 (file)
@@ -24,4 +24,21 @@ int main()
   } catch (...) {
     printf("Test 1 Fail");
   }  // { dg-output "Test 1 OK" }
+
+  nullptr_t mynull = 0;
+  try {
+    throw mynull;
+  } catch (void*) {
+    printf("Test 2 Fail");
+  } catch (bool) {
+    printf("Test 2 Fail");
+  } catch (int) {
+    printf("Test 2 Fail");
+  } catch (long int) {
+    printf("Test 2 Fail");
+  } catch (nullptr_t) {
+    printf("Test 2 OK");
+  } catch (...) {
+    printf("Test 2 Fail");
+  }  // { dg-output "Test 2 OK" }
 }
index 13cb8e3aab1e8a00e02639f0ee24795a9c347c91..d800f9869d2eb1699d67d2e0dad9b86df7ef9e83 100644 (file)
@@ -13,4 +13,8 @@ void f()
   f2(nullptr); // { dg-warning "null argument where non-null required " }
   f3("x", "y", __null); // { dg-warning "missing sentinel in function call" }
   f3("x", "y", nullptr);
+  decltype(nullptr) mynull = 0;
+  f1("%p", mynull);
+  f2(mynull); // { dg-warning "null argument where non-null required " }
+  f3("x", "y", mynull);
 }