diff options
author | Jason Merrill <jason@redhat.com> | 2025-04-12 11:35:18 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2025-04-14 23:23:05 -0400 |
commit | 764f02327f7b2dc6ac5abaf89038e51cf0ee6d13 (patch) | |
tree | a021551fdc005feaa8598389580139d879987150 /libjava/classpath/java | |
parent | fa58ff249a0e63a721ccb6d770c86523d84a212a (diff) | |
download | gcc-764f02327f7b2dc6ac5abaf89038e51cf0ee6d13.zip gcc-764f02327f7b2dc6ac5abaf89038e51cf0ee6d13.tar.gz gcc-764f02327f7b2dc6ac5abaf89038e51cf0ee6d13.tar.bz2 |
c++: shortcut constexpr vector ctor [PR113835]
Since std::vector became usable in constant evaluation in C++20, a vector
variable with static storage duration might be manifestly
constant-evaluated, so we properly try to constant-evaluate its initializer.
But it can never succeed since the result will always refer to the result of
operator new, so trying is a waste of time. Potentially a large waste of
time for a large vector, as in the testcase in the PR.
So, let's recognize this case and skip trying constant-evaluation. I do
this only for the case of an integer argument, as that's the case that's
easy to write but slow to (fail to) evaluate.
In the test, I use dg-timeout-factor to lower the default timeout from 300
seconds to 15; on my laptop, compilation without the patch takes about 20
seconds versus about 2 with the patch.
PR c++/113835
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_outermost_constant_expr): Bail out early
for std::vector(N).
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-vector1.C: New test.
Diffstat (limited to 'libjava/classpath/java')
0 files changed, 0 insertions, 0 deletions