This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/86590] Codegen is poor when passing std::string by value with _GLIBCXX_EXTERN_TEMPLATE undefined
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 20 Jul 2018 14:35:34 +0000
- Subject: [Bug libstdc++/86590] Codegen is poor when passing std::string by value with _GLIBCXX_EXTERN_TEMPLATE undefined
- Auto-submitted: auto-generated
- References: <bug-86590-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86590
--- Comment #25 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, apparently the first bullet is wherever the constant-expression
non-terminal appears in the grammar rather than that e is a constant
expression.
So the above patch really needs to be:
+ if (ctx->quiet && !ctx->maybe_constant_init)
+ {
+ *non_constant_p = true;
+ return t;
+ }
where ctx->maybe_constant_init flag would be set in some special variant of
maybe_constant_init_1. store_init_value has:
/* In C++11 constant expression is a semantic, not syntactic, property.
In C++98, make sure that what we thought was a constant expression at
template definition time is still constant and otherwise perform this
as optimization, e.g. to fold SIZEOF_EXPRs in the initializer. */
if (decl_maybe_constant_var_p (decl) || TREE_STATIC (decl))
{
bool const_init;
tree oldval = value;
value = fold_non_dependent_expr (value);
if (DECL_DECLARED_CONSTEXPR_P (decl)
|| (DECL_IN_AGGR_P (decl)
&& DECL_INITIALIZED_IN_CLASS_P (decl)
&& !DECL_VAR_DECLARED_INLINE_P (decl)))
{
/* Diagnose a non-constant initializer for constexpr variable or
non-inline in-class-initialized static data member. */
if (!require_constant_expression (value))
value = error_mark_node;
else
value = cxx_constant_init (value, decl);
}
else
value = maybe_constant_init (value, decl);
and the cxx_constant_init call there already sets ctx->quiet to false, so the
maybe_constant_init call here is probably the one that would need to be
changed.
There are tons of other maybe_constant_init calls in the C++ FE though, and it
is unclear if any other would need changes (wonder e.g. about aggregate
initializers or initializer-list etc. that contain many separate expressions;
if we need is_constant_evaluated to be true sometimes in there, it would need
to check if they are all constant expressions).