]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ginclude: stdalign.h should define __xxx_is_defined macros for C++
authorJonathan Wakely <jwakely@redhat.com>
Tue, 22 Oct 2024 15:26:27 +0000 (16:26 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 23 Oct 2024 18:45:10 +0000 (19:45 +0100)
The __alignas_is_defined macro has been required by C++ since C++11, and
C++ Library DR 4036 clarified that __alignof_is_defined should be
defined too. The whole <stdalign.h> header was deprecated for C++23 (see
LWG 3827) and is likely to be removed for C++26 (see P3348), but we can
deal with that later.

The macros alignas and alignof should not be defined, as they're
keywords in C++.

gcc/ChangeLog:

* ginclude/stdalign.h (__alignas_is_defined): Define for C++.
(__alignof_is_defined): Likewise.

libstdc++-v3/ChangeLog:

* testsuite/18_support/headers/cstdalign/macros.cc: New test.

gcc/ginclude/stdalign.h
libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc [new file with mode: 0644]

index 5f82f2d68f271758e69343ddecc14d0d36ad3cdd..980b1bba4e2c7ec6bb47b599730a06a569cf1b41 100644 (file)
@@ -26,12 +26,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #ifndef _STDALIGN_H
 #define _STDALIGN_H
 
-#if (!defined __cplusplus                                              \
-     && !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L))
+#if !(defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L)
 
+#ifndef __cplusplus
 #define alignas _Alignas
 #define alignof _Alignof
+#endif
 
+/* These are defined for C++, but deprecated in C++23.  */
 #define __alignas_is_defined 1
 #define __alignof_is_defined 1
 
diff --git a/libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc b/libstdc++-v3/testsuite/18_support/headers/cstdalign/macros.cc
new file mode 100644 (file)
index 0000000..c50c921
--- /dev/null
@@ -0,0 +1,24 @@
+// { dg-options "-D_GLIBCXX_USE_DEPRECATED=1 -Wno-deprecated" }
+// { dg-do preprocess { target c++11 } }
+
+#include <cstdalign>
+
+#ifndef __alignas_is_defined
+# error "The header <cstdalign> fails to define a macro named  __alignas_is_defined"
+#elif __alignas_is_defined != 1
+# error "__alignas_is_defined is not defined to 1 in <cstdalign>"
+#endif
+
+#ifndef __alignof_is_defined
+# error "The header <cstdalign> fails to define a macro named __alignof_is_defined"
+#elif __alignof_is_defined != 1
+# error "__alignof_is_defined is not defined to 1 in <cstdalign>"
+#endif
+
+#ifdef alignas
+# error "The header <cstdalign> defines a macro named alignas"
+#endif
+
+#ifdef alignof
+# error "The header <cstdalign> defines a macro named alignof"
+#endif