mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 08:22:16 +01:00 
			
		
		
		
	glib/gmacros: Always define NULL as nullptr in C++11 and newer
This commit is contained in:
		| @@ -870,10 +870,17 @@ | |||||||
|  */ |  */ | ||||||
| #ifndef NULL | #ifndef NULL | ||||||
| #  ifdef __cplusplus | #  ifdef __cplusplus | ||||||
|  | #    if __cplusplus >= 201103L | ||||||
|  | #      define NULL (nullptr) | ||||||
|  | #    else | ||||||
| #      define NULL (0L) | #      define NULL (0L) | ||||||
|  | #    endif /* __cplusplus >= 201103L */ | ||||||
| #  else /* !__cplusplus */ | #  else /* !__cplusplus */ | ||||||
| #  define NULL        ((void*) 0) | #  define NULL        ((void*) 0) | ||||||
| #  endif /* !__cplusplus */ | #  endif /* !__cplusplus */ | ||||||
|  | #elif defined (__cplusplus) && __cplusplus >= 201103L | ||||||
|  | #  undef NULL | ||||||
|  | #  define NULL (nullptr) | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifndef	FALSE | #ifndef	FALSE | ||||||
|   | |||||||
| @@ -34,21 +34,12 @@ test_typeof (void) | |||||||
|   MyObject *obj3 = g_atomic_pointer_get (&obj2); |   MyObject *obj3 = g_atomic_pointer_get (&obj2); | ||||||
|   g_assert_true (obj3 == obj); |   g_assert_true (obj3 == obj); | ||||||
|  |  | ||||||
| #if __cplusplus >= 201103L |  | ||||||
|   MyObject *obj4 = nullptr; |  | ||||||
| #else |  | ||||||
|   MyObject *obj4 = NULL; |   MyObject *obj4 = NULL; | ||||||
| #endif |  | ||||||
|   g_atomic_pointer_set (&obj4, obj3); |   g_atomic_pointer_set (&obj4, obj3); | ||||||
|   g_assert_true (obj4 == obj); |   g_assert_true (obj4 == obj); | ||||||
|  |  | ||||||
| #if __cplusplus >= 201103L |  | ||||||
|   MyObject *obj5 = nullptr; |  | ||||||
|   g_atomic_pointer_compare_and_exchange (&obj5, nullptr, obj4); |  | ||||||
| #else |  | ||||||
|   MyObject *obj5 = NULL; |   MyObject *obj5 = NULL; | ||||||
|   g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4); |   g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4); | ||||||
| #endif |  | ||||||
|   g_assert_true (obj5 == obj); |   g_assert_true (obj5 == obj); | ||||||
|  |  | ||||||
|   MyObject *obj6 = g_steal_pointer (&obj5); |   MyObject *obj6 = g_steal_pointer (&obj5); | ||||||
| @@ -195,11 +186,7 @@ test_steal_pointer (void) | |||||||
| int | int | ||||||
| main (int argc, char *argv[]) | main (int argc, char *argv[]) | ||||||
| { | { | ||||||
| #if __cplusplus >= 201103L |  | ||||||
|   g_test_init (&argc, &argv, nullptr); |  | ||||||
| #else |  | ||||||
|   g_test_init (&argc, &argv, NULL); |   g_test_init (&argc, &argv, NULL); | ||||||
| #endif |  | ||||||
|  |  | ||||||
|   g_test_add_func ("/C++/typeof", test_typeof); |   g_test_add_func ("/C++/typeof", test_typeof); | ||||||
|   g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange); |   g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user