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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:ceae6a13366d9646e172fc943fe8e221b70f0920

commit r10-8124-gceae6a13366d9646e172fc943fe8e221b70f0920
Author: Marek Polacek <pola...@redhat.com>
Date:   Fri May 8 11:04:29 2020 -0400

    c++: Parenthesized-init of aggregates accepts invalid code [PR94885]

    Here we have (conceptually *) something like

      struct B { };
      struct D : B { };
      D(0); // invalid

    and in C++20 the ()-initialization has created a { 0 } constructor that
    it tries to initialize an object of type D with.  We should reject
    initializing an object of type B from 0, but we wrongly accept it because
    process_init_constructor_record skips initializers for empty bases/fields:
           if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field))
               && !TREE_SIDE_EFFECTS (next))
             /* Don't add trivial initialization of an empty base/field to the
                constructor, as they might not be ordered the way the back-end
                expects.  */
             continue;
    but here 'next' was error_mark_node, returned by massage_elt_init, so we
    wound up with { } which would validly value-initialize the object.

    [*] Usually digest_init in build_new_method_call_1 would detect this,
    but in this case the instance is is_dummy_object and we don't call
    digest just yet.

            PR c++/94885
            * typeck2.c (process_init_constructor_record): Return
PICFLAG_ERRONEOUS
            if an initializer element was erroneous.

            * g++.dg/cpp2a/paren-init26.C: New test.

Reply via email to