[Bug c++/93711] New: ICE: [[no_unique_address] when constructing via template helper

eteran at alum dot rit.edu gcc-bugzilla@gcc.gnu.org
Wed Feb 12 18:23:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93711

            Bug ID: 93711
           Summary: ICE: [[no_unique_address] when constructing via
                    template helper
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eteran at alum dot rit.edu
  Target Milestone: ---

This is a little hard to explain clearly, but I'll do my best.

I have a container class that I want to make properly allocator aware and ran
into this ICE. When I don't use allocator_traits, and directly copy the
allocator, it works just fine. But once I introduce the usage of
allocator_traits<A>::select_on_container_copy_construction, I get an ICE.

Example A (Works Properly):


        #include <memory>

        template <class T, class A = std::allocator<T>>
        struct MyType {

                MyType(const MyType &other)
                        : a_(other.a_) {
                }

                MyType(const A &a = A())
                        : a_(a) {
                }

                T *p_;
                [[no_unique_address]] A a_;
        };

        int main() {
                MyType<int> x;
                MyType<int> y(x);
        }

Example B (ICE):


        #include <memory>

        template <class T, class A = std::allocator<T>>
        struct MyType {

                MyType(const MyType &other)
                        :
a_(std::allocator_traits<A>::select_on_container_copy_construction(other.a_)) {
                }

                MyType(const A &a = A())
                        :
a_(std::allocator_traits<A>::select_on_container_copy_construction(a)) {
                }

                T *p_;
                [[no_unique_address]] A a_;
        };

        int main() {
                MyType<int> x;
                MyType<int> y(x);
        }

Both cases work correctly if I remove [[no_unique_address], so it seems to be
an interaction between [[no_unique_address]] and
a_(std::allocator_traits<A>::select_on_container_copy_construction(a)).


Here is the complete backtrace for the failing example:


g++ -std=c++17 test.cpp -o test
during RTL pass: expand
test.cpp: In constructor ‘MyType<T, A>::MyType(const A&) [with T = int; A =
std::allocator<int>]’:
test.cpp:12:74: internal compiler error: in assign_temp, at function.c:982
   12 |   :
a_(std::allocator_traits<A>::select_on_container_copy_construction(a)) {
      |                                                                        
 ^
0x59a442 assign_temp(tree_node*, int, int)
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/function.c:982
0x7c050f expand_call(tree_node*, rtx_def*, int)
        /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/calls.c:3459
0x8c4a2d expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
        /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/expr.c:11033
0x8d297b expand_normal
        /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/expr.h:285
0x8d297b store_field
        /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/expr.c:7022
0x8cff37 expand_assignment(tree_node*, tree_node*, bool)
        /var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/expr.c:5296
0x7cc3f0 expand_call_stmt
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/cfgexpand.c:2722
0x7cc3f0 expand_gimple_stmt_1
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/cfgexpand.c:3691
0x7cc3f0 expand_gimple_stmt
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/cfgexpand.c:3850
0x7d1237 expand_gimple_basic_block
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/cfgexpand.c:5890
0x7d35d7 execute
       
/var/tmp/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/gcc/cfgexpand.c:6513
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.


More information about the Gcc-bugs mailing list