https://gcc.gnu.org/g:89c1412dfc26d141a6d8732b269c3e30eff44613

commit r17-3213-g89c1412dfc26d141a6d8732b269c3e30eff44613
Author: Jakub Jelinek <[email protected]>
Date:   Wed Aug 12 10:02:37 2026 +0200

    c++: Change alignof (decltype (^^::)) from 1 to alignof (void *)
    
    We IMHO incorrectly leave TYPE_ALIGN of std::meta::info unset, so alignof on
    it is 1.  We should change that to the same as decltype (nullptr) and
    void *.
    As C++26 is heavily experimental, this is changed unconditionally, without
    -fabi-version= checks, and only for 17, not for 16.x.
    
    2026-08-12  Jakub Jelinek  <[email protected]>
    
            * reflect.cc (init_reflection): Also initialize TYPE_UNSIGNED,
            TYPE_PRECISION, TYPE_MODE and TYPE_ALIGN of meta_info_type_node.
    
            * g++.dg/reflect/info1.C: New test.
    
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 gcc/cp/reflect.cc                    | 4 ++++
 gcc/testsuite/g++.dg/reflect/info1.C | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index cfb9292849fc..be3c2c5f86cc 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -65,6 +65,10 @@ init_reflection ()
   /* Make it a complete type.  */
   TYPE_SIZE (meta_info_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
   TYPE_SIZE_UNIT (meta_info_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
+  TYPE_UNSIGNED (meta_info_type_node) = 1;
+  TYPE_PRECISION (meta_info_type_node) = GET_MODE_BITSIZE (ptr_mode);
+  SET_TYPE_MODE (meta_info_type_node, ptr_mode);
+  SET_TYPE_ALIGN (meta_info_type_node, GET_MODE_ALIGNMENT (ptr_mode));
   /* Name it.  */
   record_builtin_type (RID_MAX, "decltype(^^int)", meta_info_type_node);
 
diff --git a/gcc/testsuite/g++.dg/reflect/info1.C 
b/gcc/testsuite/g++.dg/reflect/info1.C
new file mode 100644
index 000000000000..17d4d2f02288
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/info1.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+using info = decltype (^^::);
+static_assert (sizeof (info) == sizeof (void *));
+static_assert (alignof (info) == alignof (void *));

Reply via email to