* cvt.c (cp_convert_to_pointer): Use null_ptr_cst_p.
* typeck.c (build_ptrmemfunc): Likewise.
From-SVN: r160309
+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
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,
}
/* 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,
+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.
char* const cp1 = nullptr;
char* const cp2 = __null;
char* const cp3 = 0;
+decltype(nullptr) mynull = 0;
+char* const cp4 = mynull;
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;
// 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 " }
+
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;
const pmf pmf1 = nullptr;
const pmf pmf2 = __null;
const pmf pmf3 = 0;
+decltype(nullptr) mynull = 0;
+const pmf pmf4 = mynull;
void fun()
{
assert_true(cp1 == nullptr);
+ decltype(nullptr) mynull = 0;
+ assert_true(cp1 == mynull);
}
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 " }
}
void fun()
{
assert_true(nullptr ? false : true);
+ decltype(nullptr) mynull = 0;
+ assert_true(mynull ? false : true);
}
void fun()
{
if( nullptr == 0 );
+ decltype(nullptr) mynull = 0;
+ if( mynull == 0 );
}
{
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 " }
}
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);
}
// 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");
#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));
}
//
type_equal<char*>(f(nullptr));
type_equal<int>(f(0));
+ decltype(nullptr) mynull = 0;
+ type_equal<char*>(f(mynull));
}
//
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));
}
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));
}
{
// Overload to bool, not int
type_equal<bool>(i(nullptr));
+ decltype(nullptr) mynull = 0;
+ type_equal<bool>(i(mynull));
}
void test_j()
{
type_equal<char*>(j(nullptr));
+ decltype(nullptr) mynull = 0;
+ type_equal<char*>(j(mynull));
}
{
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;
}
} 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" }
}
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);
}