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
This commit is contained in:
Magnus Fromreide 2010-06-05 06:52:18 +02:00 committed by Jason Merrill
parent 247078ec4d
commit 33c2474d70
25 changed files with 132 additions and 4 deletions

View 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

View 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,

View 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,

View 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.

View 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;

View 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;

View 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 " }

View 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;

View 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;

View File

@ -10,4 +10,6 @@ char* const cp1 = nullptr;
void fun()
{
assert_true(cp1 == nullptr);
decltype(nullptr) mynull = 0;
assert_true(cp1 == mynull);
}

View 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 " }
}

View File

@ -8,4 +8,6 @@
void fun()
{
assert_true(nullptr ? false : true);
decltype(nullptr) mynull = 0;
assert_true(mynull ? false : true);
}

View File

@ -6,4 +6,6 @@
void fun()
{
if( nullptr == 0 );
decltype(nullptr) mynull = 0;
if( mynull == 0 );
}

View 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 " }
}

View 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);
}

View 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");

View 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));
}

View 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));
}

View 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));
}

View 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));
}

View 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));
}

View 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));
}

View 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;
}

View 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" }
}

View 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);
}