blob: 63cbf90ab233185011c08eb64e3f8ce08e8bd008 [file] [log] [blame]
Patrick Williams7784c422022-11-17 07:29:11 -06001From 0ca5254c5d92aec675b76b4bfa72a6885cde6066 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
3Date: Sat, 29 Oct 2022 04:30:52 +0200
4Subject: [PATCH] glib/gmacros: Always define NULL as nullptr in C++11 and
5 newer
6
7Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/commit/0ca5254c5d92aec675b76b4bfa72a6885cde6066]
8Signed-off-by: Alexander Kanavin <alex@linutronix.de>
9---
10 glib/gmacros.h | 9 ++++++++-
11 glib/tests/cxx.cpp | 13 -------------
12 2 files changed, 8 insertions(+), 14 deletions(-)
13
14diff --git a/glib/gmacros.h b/glib/gmacros.h
15index 5302841105..9fe8270822 100644
16--- a/glib/gmacros.h
17+++ b/glib/gmacros.h
18@@ -870,10 +870,17 @@
19 */
20 #ifndef NULL
21 # ifdef __cplusplus
22-# define NULL (0L)
23+# if __cplusplus >= 201103L
24+# define NULL (nullptr)
25+# else
26+# define NULL (0L)
27+# endif /* __cplusplus >= 201103L */
28 # else /* !__cplusplus */
29 # define NULL ((void*) 0)
30 # endif /* !__cplusplus */
31+#elif defined (__cplusplus) && __cplusplus >= 201103L
32+# undef NULL
33+# define NULL (nullptr)
34 #endif
35
36 #ifndef FALSE
37diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp
38index 6ac60791c8..045457c6e2 100644
39--- a/glib/tests/cxx.cpp
40+++ b/glib/tests/cxx.cpp
41@@ -34,21 +34,12 @@ test_typeof (void)
42 MyObject *obj3 = g_atomic_pointer_get (&obj2);
43 g_assert_true (obj3 == obj);
44
45-#if __cplusplus >= 201103L
46- MyObject *obj4 = nullptr;
47-#else
48 MyObject *obj4 = NULL;
49-#endif
50 g_atomic_pointer_set (&obj4, obj3);
51 g_assert_true (obj4 == obj);
52
53-#if __cplusplus >= 201103L
54- MyObject *obj5 = nullptr;
55- g_atomic_pointer_compare_and_exchange (&obj5, nullptr, obj4);
56-#else
57 MyObject *obj5 = NULL;
58 g_atomic_pointer_compare_and_exchange (&obj5, NULL, obj4);
59-#endif
60 g_assert_true (obj5 == obj);
61
62 MyObject *obj6 = g_steal_pointer (&obj5);
63@@ -195,11 +186,7 @@ test_steal_pointer (void)
64 int
65 main (int argc, char *argv[])
66 {
67-#if __cplusplus >= 201103L
68- g_test_init (&argc, &argv, nullptr);
69-#else
70 g_test_init (&argc, &argv, NULL);
71-#endif
72
73 g_test_add_func ("/C++/typeof", test_typeof);
74 g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange);
75--
76GitLab
77