Bug 65591 - G++ should use default constructor for {}-init when possible
Summary: G++ should use default constructor for {}-init when possible
Status: RESOLVED DUPLICATE of bug 92385
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on: 65154 65503
Blocks:
  Show dependency treegraph
 
Reported: 2015-03-26 20:19 UTC by Jason Merrill
Modified: 2022-01-07 05:23 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Merrill 2015-03-26 20:19:16 UTC
From Mikhail Maltsev's comment 5 on Bug #65154:

But it reveals some latent bug (PR65503). In the following case (after applying the patch):

struct ss {
    ss() {};
};
struct C {
      ss s[1000];
};
int main() {
      C cs[5]{};
}

We'll get 1000 calls to ss() in main instead of calling default c-tor of struct C. (which is probably not what we want).

-----

I agree that we want to call the default constructor in this case, and let the inliner decide from there.  This is not the same issue as bug 65503.
Comment 1 Richard Biener 2015-03-27 08:38:49 UTC
Confirmed.
Comment 2 Jason Merrill 2015-03-27 15:26:55 UTC
Actually, the standard (8.5.1/8.5.4) says we need to do aggregate initialization here, so this is either a language issue or a duplicate of bug 65503.
Comment 3 Andrew Pinski 2021-07-23 01:31:25 UTC
We should be able to do a loop instead of 1000 calls though.
Comment 4 Andrew Pinski 2022-01-07 00:55:06 UTC
Note I thought the patch which fixes PR 92385 would fix this one but instead we are getting an ICE which I filed as PR 103936. I suspect after that is fixed this will also be fixed.
Comment 5 Jason Merrill 2022-01-07 02:56:14 UTC
Yes, this is fixed by r12-6326.  And then broken again by r12-6329, which I'll address in the new PR.

*** This bug has been marked as a duplicate of bug 92385 ***
Comment 6 GCC Commits 2022-01-07 05:23:03 UTC
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:765693be1c8dc91fe612e7a499c5e41ba398ab96

commit r12-6339-g765693be1c8dc91fe612e7a499c5e41ba398ab96
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 6 21:58:01 2022 -0500

    c++: temporarily restore VEC_INIT_EXPR gimplify [PR103936]
    
    PR103936 demonstrates that some VEC_INIT_EXPR can still survive into
    GENERIC; until that's fixed let's put back the handling in cp_gimplify_expr.
    
            PR c++/103936
            PR c++/65591
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.c (cp_gimplify_expr): Restore VEC_INIT_EXPR handling.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/init/aggr15.C: New test.