From 33c2474d7055ff84f60b57727b640cbaa7dd8caa Mon Sep 17 00:00:00 2001 From: Magnus Fromreide Date: Sat, 5 Jun 2010 06:52:18 +0200 Subject: [PATCH] cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p. * cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p. * typeck.c (build_ptrmemfunc): Likewise. From-SVN: r160309 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/cvt.c | 2 +- gcc/cp/typeck.c | 2 +- gcc/testsuite/ChangeLog | 25 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nullptr01.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr02.C | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/nullptr03.C | 5 ++++- gcc/testsuite/g++.dg/cpp0x/nullptr04.C | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/nullptr05.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr06.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr07.C | 3 +++ gcc/testsuite/g++.dg/cpp0x/nullptr08.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr09.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr10.C | 4 ++++ gcc/testsuite/g++.dg/cpp0x/nullptr11.C | 23 +++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nullptr12.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr13.C | 5 +++++ gcc/testsuite/g++.dg/cpp0x/nullptr14.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr15.C | 3 +++ gcc/testsuite/g++.dg/cpp0x/nullptr16.C | 3 +++ gcc/testsuite/g++.dg/cpp0x/nullptr17.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr18.C | 2 ++ gcc/testsuite/g++.dg/cpp0x/nullptr20.C | 5 ++++- gcc/testsuite/g++.dg/cpp0x/nullptr21.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/nullptr22.C | 4 ++++ 25 files changed, 132 insertions(+), 4 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b0510792fcf..9c4ad0ae569 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2010-06-04 Magnus Fromreide + + * cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p. + * typeck.c (build_ptrmemfunc): Likewise. + 2010-06-04 Jason Merrill * typeck2.c (merge_exception_specifiers): Adjust merging of diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 71315b1f4fd..4aee15111ed 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -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, diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 26ffe1cc416..53e84cf5a40 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0998820f7d0..accf2e37dee 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,28 @@ +2010-06-04 Magnus Fromreide + + * 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 * g++.dg/cpp0x/noexcept06.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr01.C b/gcc/testsuite/g++.dg/cpp0x/nullptr01.C index 8de877bab50..de3860c9ea4 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr01.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr01.C @@ -6,3 +6,5 @@ char* const cp1 = nullptr; char* const cp2 = __null; char* const cp3 = 0; +decltype(nullptr) mynull = 0; +char* const cp4 = mynull; diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr02.C b/gcc/testsuite/g++.dg/cpp0x/nullptr02.C index 2272152cf73..80977cb2f00 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr02.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr02.C @@ -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; diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr03.C b/gcc/testsuite/g++.dg/cpp0x/nullptr03.C index 1c9e521bd88..b6df8963740 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr03.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr03.C @@ -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 " } + diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr04.C b/gcc/testsuite/g++.dg/cpp0x/nullptr04.C index 28e37156f8c..6e1d1256c57 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr04.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr04.C @@ -11,3 +11,9 @@ const int n4 = static_cast(nullptr); // { dg-error "invalid static_ca const short int n5 = reinterpret_cast(nullptr); // { dg-error "loses precision" } const ssize_t n6 = reinterpret_cast(nullptr); const ssize_t n7 = (ssize_t)nullptr; + +decltype(nullptr) mynull = 0; +const int n8 = static_cast(mynull); // { dg-error "invalid static_cast " } +const short int n9 = reinterpret_cast(mynull); // { dg-error "loses precision" } +const ssize_t n10 = reinterpret_cast(mynull); +const ssize_t n11 = (ssize_t)mynull; diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr05.C b/gcc/testsuite/g++.dg/cpp0x/nullptr05.C index 7c3f8b7093d..22a8b51c1c7 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr05.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr05.C @@ -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; diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr06.C b/gcc/testsuite/g++.dg/cpp0x/nullptr06.C index 5dea1fbf171..c50bb9bc113 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr06.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr06.C @@ -10,4 +10,6 @@ char* const cp1 = nullptr; void fun() { assert_true(cp1 == nullptr); + decltype(nullptr) mynull = 0; + assert_true(cp1 == mynull); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr07.C b/gcc/testsuite/g++.dg/cpp0x/nullptr07.C index cebed8862df..64d442be331 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr07.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr07.C @@ -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 " } } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr08.C b/gcc/testsuite/g++.dg/cpp0x/nullptr08.C index d7d9169f5a1..1e5db278ddf 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr08.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr08.C @@ -8,4 +8,6 @@ void fun() { assert_true(nullptr ? false : true); + decltype(nullptr) mynull = 0; + assert_true(mynull ? false : true); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr09.C b/gcc/testsuite/g++.dg/cpp0x/nullptr09.C index a42821cbfa6..b35a3c3207d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr09.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr09.C @@ -6,4 +6,6 @@ void fun() { if( nullptr == 0 ); + decltype(nullptr) mynull = 0; + if( mynull == 0 ); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr10.C b/gcc/testsuite/g++.dg/cpp0x/nullptr10.C index cd131864a33..fa32267ec02 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr10.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr10.C @@ -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 " } } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr11.C b/gcc/testsuite/g++.dg/cpp0x/nullptr11.C index 85402a1a2a3..5907816a847 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr11.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr11.C @@ -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); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr12.C b/gcc/testsuite/g++.dg/cpp0x/nullptr12.C index f68652c999e..1713259f103 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr12.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr12.C @@ -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"); diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr13.C b/gcc/testsuite/g++.dg/cpp0x/nullptr13.C index 633e971feca..a9377584c56 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr13.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr13.C @@ -5,7 +5,12 @@ #include +#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)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr14.C b/gcc/testsuite/g++.dg/cpp0x/nullptr14.C index 0493bcca006..4c4627b541b 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr14.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr14.C @@ -20,4 +20,6 @@ void test_f() // type_equal(f(nullptr)); type_equal(f(0)); + decltype(nullptr) mynull = 0; + type_equal(f(mynull)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr15.C b/gcc/testsuite/g++.dg/cpp0x/nullptr15.C index abb45f4e937..67d9d4a2311 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr15.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr15.C @@ -18,4 +18,7 @@ void test_g() // g(nullptr); // { dg-error "no matching function for call to " } type_equal(g((float*)nullptr)); + decltype(nullptr) mynull = 0; + g(mynull); // { dg-error "no matching function for call to " } + type_equal(g((float*)mynull)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr16.C b/gcc/testsuite/g++.dg/cpp0x/nullptr16.C index 7561b21cfe3..0ec0b6a12b6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr16.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr16.C @@ -19,4 +19,7 @@ void test_h() type_equal(h(0)); type_equal(h(nullptr)); type_equal(h((float*)nullptr)); + nullptr_t mynull = 0; + type_equal(h(mynull)); + type_equal(h((float*)mynull)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr17.C b/gcc/testsuite/g++.dg/cpp0x/nullptr17.C index acedbae3787..2e580557bc3 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr17.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr17.C @@ -18,4 +18,6 @@ void test_i() { // Overload to bool, not int type_equal(i(nullptr)); + decltype(nullptr) mynull = 0; + type_equal(i(mynull)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr18.C b/gcc/testsuite/g++.dg/cpp0x/nullptr18.C index 192b646efb4..b8fa38c718d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr18.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr18.C @@ -16,4 +16,6 @@ bool j( bool ); void test_j() { type_equal(j(nullptr)); + decltype(nullptr) mynull = 0; + type_equal(j(mynull)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr20.C b/gcc/testsuite/g++.dg/cpp0x/nullptr20.C index a959b00786f..3e58406770d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr20.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr20.C @@ -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; } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr21.C b/gcc/testsuite/g++.dg/cpp0x/nullptr21.C index 84c34dd1e0a..c30cb3c8b6d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr21.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr21.C @@ -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" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr22.C b/gcc/testsuite/g++.dg/cpp0x/nullptr22.C index 13cb8e3aab1..d800f9869d2 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr22.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr22.C @@ -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); } -- 2.30.2