]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: mangling union{1} in template [PR104847]
authorJason Merrill <jason@redhat.com>
Sun, 27 Mar 2022 00:10:19 +0000 (20:10 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 28 Mar 2022 13:35:58 +0000 (09:35 -0400)
My implementation of union non-type template arguments in r11-2016 broke
braced casts of union type, because they are still in syntactic (undigested)
form.

PR c++/104847

gcc/cp/ChangeLog:

* mangle.cc (write_expression): Don't write a union designator when
undigested.

gcc/testsuite/ChangeLog:

* g++.dg/abi/mangle-union1.C: New test.

gcc/cp/mangle.cc
gcc/testsuite/g++.dg/abi/mangle-union1.C [new file with mode: 0644]

index dbcec0a55bc3ff230185bfcc43f99f4f89776827..eb53e0ebeb435f011e5d53177908e852212f601f 100644 (file)
@@ -3363,7 +3363,7 @@ write_expression (tree expr)
                  {
                    if (i > last_nonzero)
                      break;
-                   if (TREE_CODE (etype) == UNION_TYPE)
+                   if (!undigested && TREE_CODE (etype) == UNION_TYPE)
                      {
                        /* Express the active member as a designator.  */
                        write_string ("di");
diff --git a/gcc/testsuite/g++.dg/abi/mangle-union1.C b/gcc/testsuite/g++.dg/abi/mangle-union1.C
new file mode 100644 (file)
index 0000000..f2ee457
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/104847
+// { dg-do compile { target c++11 } }
+
+struct S { int i; };
+union U { S k; };
+template <class T, class... Ts> T sink(T&&, Ts&&...);
+template <class T>
+decltype(sink(U{1},T())) f(T) { return U{1}; }
+int main() { f(3); }
+// { dg-final { scan-assembler "_Z1fIiEDTcl4sinktl1ULi1EEcvT__EEES1_" } }