]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with nested anonymous union [PR117153]
authorMarek Polacek <polacek@redhat.com>
Mon, 25 Nov 2024 14:45:13 +0000 (09:45 -0500)
committerMarek Polacek <polacek@redhat.com>
Fri, 24 Jan 2025 17:22:10 +0000 (12:22 -0500)
commit10850f92b2a618ef1b1ad399530943ef4847823d
tree2bbd1a6ac3b3beaa625ebd29971dcd2d3e69ea53
parent41a6d4f8aa659dd88fce2d831306affc91ba4d53
c++: ICE with nested anonymous union [PR117153]

In a template, for

  union {
    union {
      T d;
    };
  };

build_anon_union_vars crates a malformed COMPONENT_REF: we have no
DECL_NAME for the nested anon union so we create something like "object.".
Most of the front end doesn't seem to care, but if such a tree gets to
potential_constant_expression, it can cause a crash.

We can use FIELD directly for the COMPONENT_REF's member.  tsubst_stmt
should build up a proper one in:

    if (VAR_P (decl) && !DECL_NAME (decl)
&& ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
      /* Anonymous aggregates are a special case.  */
      finish_anon_union (decl);

PR c++/117153

gcc/cp/ChangeLog:

* decl2.cc (build_anon_union_vars): Use FIELD for the second operand
of a COMPONENT_REF.

gcc/testsuite/ChangeLog:

* g++.dg/other/anon-union6.C: New test.
* g++.dg/other/anon-union7.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl2.cc
gcc/testsuite/g++.dg/other/anon-union6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/anon-union7.C [new file with mode: 0644]