1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -ffreestanding -Wno-null-conversion -Wno-tautological-compare %s
4 typedef typeof(nullptr) nullptr_t
;
8 __attribute__((overloadable
)) int o1(char*);
9 __attribute__((overloadable
)) void o1(uintptr_t);
11 nullptr_t
f(nullptr_t null
)
13 // Implicit conversions.
22 // Can't convert nullptr to integral implicitly.
23 uintptr_t i
= nullptr; // expected-error-re {{initializing 'uintptr_t' (aka '{{.*}}') with an expression of incompatible type 'nullptr_t'}}
26 (void)(null
== nullptr);
27 (void)(null
<= nullptr); // expected-error {{invalid operands to binary expression}}
29 (void)(null
== (void*)0);
30 (void)((void*)0 == nullptr);
31 (void)(null
<= 0); // expected-error {{invalid operands to binary expression}}
32 (void)(null
<= (void*)0); // expected-error {{invalid operands to binary expression}}
33 (void)((void*)0 <= nullptr); // expected-error {{invalid operands to binary expression}}
36 (void)(nullptr <= 0); // expected-error {{invalid operands to binary expression}}
37 (void)(0 <= nullptr); // expected-error {{invalid operands to binary expression}}
38 (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
39 (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
40 (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
41 (void)(0 ? nullptr : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
42 (void)(0 ? nullptr : (void*)0);
43 (void)(0 ? nullptr : (struct A
){}); // expected-error {{non-pointer operand type 'struct A' incompatible with nullptr}}
44 (void)(0 ? (struct A
){} : nullptr); // expected-error {{non-pointer operand type 'struct A' incompatible with nullptr}}
50 // nullptr is an rvalue, null is an lvalue
51 (void)&nullptr; // expected-error {{cannot take the address of an rvalue of type 'nullptr_t'}}
52 nullptr_t
*pn
= &null
;
58 __attribute__((overloadable
)) void *g(void*);
59 __attribute__((overloadable
)) bool g(bool);
61 // Test that we prefer g(void*) over g(bool).
62 static_assert(__builtin_types_compatible_p(typeof(g(nullptr)), void *), "");
64 void sent(int, ...) __attribute__((sentinel
));
67 // nullptr can be used as the sentinel value.
71 void printf(const char*, ...) __attribute__((format(printf
, 1, 2)));
74 // Don't warn when using nullptr with %p.
75 printf("%p", nullptr);
78 static_assert(sizeof(nullptr_t
) == sizeof(void*), "");
80 static_assert(!nullptr, "");
81 static_assert(!(bool){nullptr}, "");
83 static_assert(!(nullptr < nullptr), ""); // expected-error {{invalid operands to binary expression}}
84 static_assert(!(nullptr > nullptr), ""); // expected-error {{invalid operands to binary expression}}
85 static_assert( nullptr <= nullptr, ""); // expected-error {{invalid operands to binary expression}}
86 static_assert( nullptr >= nullptr, ""); // expected-error {{invalid operands to binary expression}}
87 static_assert( nullptr == nullptr, "");
88 static_assert(!(nullptr != nullptr), "");
90 static_assert(!(0 < nullptr), ""); // expected-error {{invalid operands to binary expression}}
91 static_assert(!(0 > nullptr), ""); // expected-error {{invalid operands to binary expression}}
92 static_assert( 0 <= nullptr, ""); // expected-error {{invalid operands to binary expression}}
93 static_assert( 0 >= nullptr, ""); // expected-error {{invalid operands to binary expression}}
94 static_assert( 0 == nullptr, "");
95 static_assert(!(0 != nullptr), "");
97 static_assert(!(nullptr < 0), ""); // expected-error {{invalid operands to binary expression}}
98 static_assert(!(nullptr > 0), ""); // expected-error {{invalid operands to binary expression}}
99 static_assert( nullptr <= 0, ""); // expected-error {{invalid operands to binary expression}}
100 static_assert( nullptr >= 0, ""); // expected-error {{invalid operands to binary expression}}
101 static_assert( nullptr == 0, "");
102 static_assert(!(nullptr != 0), "");
104 __attribute__((overloadable
)) int f1(int*);
105 __attribute__((overloadable
)) float f1(bool);
108 int ir
= (f1
)(nullptr);