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:
parent
247078ec4d
commit
33c2474d70
|
@ -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>
|
2010-06-04 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
* typeck2.c (merge_exception_specifiers): Adjust merging of
|
* typeck2.c (merge_exception_specifiers): Adjust merging of
|
||||||
|
|
|
@ -196,7 +196,7 @@ cp_convert_to_pointer (tree type, tree expr)
|
||||||
return error_mark_node;
|
return error_mark_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (integer_zerop (expr))
|
if (null_ptr_cst_p (expr))
|
||||||
{
|
{
|
||||||
if (TYPE_PTRMEMFUNC_P (type))
|
if (TYPE_PTRMEMFUNC_P (type))
|
||||||
return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
|
return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
|
||||||
|
|
|
@ -7039,7 +7039,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle null pointer to member function conversions. */
|
/* 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);
|
pfn = build_c_cast (input_location, type, integer_zero_node);
|
||||||
return build_ptrmemfunc1 (to_type,
|
return build_ptrmemfunc1 (to_type,
|
||||||
|
|
|
@ -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>
|
2010-06-04 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
* g++.dg/cpp0x/noexcept06.C: New.
|
* g++.dg/cpp0x/noexcept06.C: New.
|
||||||
|
|
|
@ -6,3 +6,5 @@
|
||||||
char* const cp1 = nullptr;
|
char* const cp1 = nullptr;
|
||||||
char* const cp2 = __null;
|
char* const cp2 = __null;
|
||||||
char* const cp3 = 0;
|
char* const cp3 = 0;
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
char* const cp4 = mynull;
|
||||||
|
|
|
@ -8,3 +8,9 @@ typedef decltype(nullptr) nullptr_t;
|
||||||
const nullptr_t np1 = nullptr;
|
const nullptr_t np1 = nullptr;
|
||||||
const nullptr_t np2 = __null;
|
const nullptr_t np2 = __null;
|
||||||
const nullptr_t np3 = 0;
|
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;
|
||||||
|
|
|
@ -3,4 +3,7 @@
|
||||||
|
|
||||||
// Test assignment to int
|
// 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 " }
|
||||||
|
|
||||||
|
|
|
@ -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 short int n5 = reinterpret_cast<short int>(nullptr); // { dg-error "loses precision" }
|
||||||
const ssize_t n6 = reinterpret_cast<ssize_t>(nullptr);
|
const ssize_t n6 = reinterpret_cast<ssize_t>(nullptr);
|
||||||
const ssize_t n7 = (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;
|
||||||
|
|
|
@ -10,3 +10,5 @@ typedef void (F::*pmf)();
|
||||||
const pmf pmf1 = nullptr;
|
const pmf pmf1 = nullptr;
|
||||||
const pmf pmf2 = __null;
|
const pmf pmf2 = __null;
|
||||||
const pmf pmf3 = 0;
|
const pmf pmf3 = 0;
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
const pmf pmf4 = mynull;
|
||||||
|
|
|
@ -10,4 +10,6 @@ char* const cp1 = nullptr;
|
||||||
void fun()
|
void fun()
|
||||||
{
|
{
|
||||||
assert_true(cp1 == nullptr);
|
assert_true(cp1 == nullptr);
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
assert_true(cp1 == mynull);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,7 @@ void fun()
|
||||||
if( n == nullptr ); // { dg-error "invalid operands of types " }
|
if( n == nullptr ); // { dg-error "invalid operands of types " }
|
||||||
const int m = 1;
|
const int m = 1;
|
||||||
if( m == nullptr ); // { dg-error "invalid operands of types " }
|
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 " }
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,6 @@
|
||||||
void fun()
|
void fun()
|
||||||
{
|
{
|
||||||
assert_true(nullptr ? false : true);
|
assert_true(nullptr ? false : true);
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
assert_true(mynull ? false : true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,6 @@
|
||||||
void fun()
|
void fun()
|
||||||
{
|
{
|
||||||
if( nullptr == 0 );
|
if( nullptr == 0 );
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
if( mynull == 0 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,8 @@ void fun()
|
||||||
{
|
{
|
||||||
nullptr = 0; // { dg-error "lvalue required as left operand" }
|
nullptr = 0; // { dg-error "lvalue required as left operand" }
|
||||||
nullptr + 2; // { dg-error "invalid operands of types " }
|
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 " }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,27 @@ void fun()
|
||||||
assert_false(nullptr > nullptr);
|
assert_false(nullptr > nullptr);
|
||||||
assert_true(nullptr <= nullptr);
|
assert_true(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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,3 +4,5 @@
|
||||||
// Test sizeof
|
// Test sizeof
|
||||||
|
|
||||||
static_assert(sizeof(nullptr) == sizeof(void*), "sizeof(nullptr) is wrong");
|
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");
|
||||||
|
|
|
@ -5,7 +5,12 @@
|
||||||
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#define assert_true(b) do { char c[2 * bool(b) - 1]; } while(0)
|
||||||
|
|
||||||
void fun()
|
void fun()
|
||||||
{
|
{
|
||||||
typeid(nullptr);
|
typeid(nullptr);
|
||||||
|
const decltype(nullptr) mynull = 0;
|
||||||
|
typeid(mynull);
|
||||||
|
assert_true(typeid(nullptr) == typeid(mynull));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,6 @@ void test_f()
|
||||||
//
|
//
|
||||||
type_equal<char*>(f(nullptr));
|
type_equal<char*>(f(nullptr));
|
||||||
type_equal<int>(f(0));
|
type_equal<int>(f(0));
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
type_equal<char*>(f(mynull));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,7 @@ void test_g()
|
||||||
//
|
//
|
||||||
g(nullptr); // { dg-error "no matching function for call to " }
|
g(nullptr); // { dg-error "no matching function for call to " }
|
||||||
type_equal<float*>(g((float*)nullptr));
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,7 @@ void test_h()
|
||||||
type_equal<int>(h(0));
|
type_equal<int>(h(0));
|
||||||
type_equal<nullptr_t>(h(nullptr));
|
type_equal<nullptr_t>(h(nullptr));
|
||||||
type_equal<float*>(h((float*)nullptr));
|
type_equal<float*>(h((float*)nullptr));
|
||||||
|
nullptr_t mynull = 0;
|
||||||
|
type_equal<nullptr_t>(h(mynull));
|
||||||
|
type_equal<float*>(h((float*)mynull));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,6 @@ void test_i()
|
||||||
{
|
{
|
||||||
// Overload to bool, not int
|
// Overload to bool, not int
|
||||||
type_equal<bool>(i(nullptr));
|
type_equal<bool>(i(nullptr));
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
type_equal<bool>(i(mynull));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,6 @@ bool j( bool );
|
||||||
void test_j()
|
void test_j()
|
||||||
{
|
{
|
||||||
type_equal<char*>(j(nullptr));
|
type_equal<char*>(j(nullptr));
|
||||||
|
decltype(nullptr) mynull = 0;
|
||||||
|
type_equal<char*>(j(mynull));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,11 @@ int main()
|
||||||
{
|
{
|
||||||
char buf1[64];
|
char buf1[64];
|
||||||
char buf2[64];
|
char buf2[64];
|
||||||
|
char buf3[64];
|
||||||
|
|
||||||
std::sprintf(buf1, "%p", (void*)0);
|
std::sprintf(buf1, "%p", (void*)0);
|
||||||
std::sprintf(buf2, "%p", nullptr);
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,21 @@ int main()
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
printf("Test 1 Fail");
|
printf("Test 1 Fail");
|
||||||
} // { dg-output "Test 1 OK" }
|
} // { 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" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,8 @@ void f()
|
||||||
f2(nullptr); // { dg-warning "null argument where non-null required " }
|
f2(nullptr); // { dg-warning "null argument where non-null required " }
|
||||||
f3("x", "y", __null); // { dg-warning "missing sentinel in function call" }
|
f3("x", "y", __null); // { dg-warning "missing sentinel in function call" }
|
||||||
f3("x", "y", nullptr);
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue