public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression
@ 2021-10-24 23:39 f.heckenbach@fh-soft.de
2021-10-24 23:43 ` [Bug c++/102921] " f.heckenbach@fh-soft.de
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: f.heckenbach@fh-soft.de @ 2021-10-24 23:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
Bug ID: 102921
Summary: error: modification of '<temporary>' is not a constant
expression
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: f.heckenbach@fh-soft.de
Target Milestone: ---
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102921] error: modification of '<temporary>' is not a constant expression
2021-10-24 23:39 [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression f.heckenbach@fh-soft.de
@ 2021-10-24 23:43 ` f.heckenbach@fh-soft.de
2021-10-25 8:03 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: f.heckenbach@fh-soft.de @ 2021-10-24 23:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
--- Comment #1 from Frank Heckenbach <f.heckenbach@fh-soft.de> ---
The following program, compiled with "-std=c++20" gives this error message; I
don't even understand what it's trying to tell me:
error: modification of '<temporary>' is not a constant expression
#include <initializer_list>
#include <string_view>
constexpr std::initializer_list <std::string_view> a { "" };
Other compilers seem to have no problem with it.
Digging through the headers, I could trace it (via char_traits and
__constant_string_p) to __builtin_is_constant_evaluated. The following version
gives the same error (but I'm still not sure if the problem is in the compiler
or the headers):
#include <initializer_list>
#include <type_traits>
struct S
{
constexpr S () noexcept { }
int a = std::is_constant_evaluated ();
};
constexpr std::initializer_list <S> a { { } };
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102921] error: modification of '<temporary>' is not a constant expression
2021-10-24 23:39 [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression f.heckenbach@fh-soft.de
2021-10-24 23:43 ` [Bug c++/102921] " f.heckenbach@fh-soft.de
@ 2021-10-25 8:03 ` jakub at gcc dot gnu.org
2021-10-25 8:27 ` jakub at gcc dot gnu.org
2023-06-30 14:01 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-25 8:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-10-25
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Testcase without headers:
namespace std
{
typedef decltype (sizeof 0) size_t;
template<class T>
class initializer_list
{
const T *_M_array;
size_t _M_len;
constexpr initializer_list (const T &a, size_t l) : _M_array(a), _M_len(l)
{ }
};
}
struct S
{
constexpr S () noexcept { }
int a = __builtin_is_constant_evaluated ();
};
constexpr std::initializer_list <S> a { { } };
The <temporary> is _ZGRL1a_[0] demangled reference temporary #0 for a, and the
expression that is being constant evaluated is (without cleanup points and
expr_stmt):
TARGET_EXPR <D.2197, {._M_array= (_ZGRL1a_[0] = TARGET_EXPR <D.2186, S::S
(&D.2186)>;, (const struct S *) &_ZGRL1a_;, ._M_len=1}>;
No idea how to fix that though...
Doesn't seem to be a regression, behaved this way since
r9-2311-ge408261123697a82b5965c700fa2465999f0fd62 when
__builtin_is_constant_evaluated has been introduced.
Without the builtin, bet the ctor is folded into a CONSTRUCTOR already when
performing non-manifestly constant evaluation before.
The INIT_EXPR that stores into _ZGRL1a_[0] is created by
split_nonconstant_init_1 called indirectly from set_up_extended_ref_temp, so at
that point the initializer clearly didn't go through manifestly constant
evaluation. Should that be done somewhere if set_up_extended_ref_temp is
called for a constexpr variable?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102921] error: modification of '<temporary>' is not a constant expression
2021-10-24 23:39 [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression f.heckenbach@fh-soft.de
2021-10-24 23:43 ` [Bug c++/102921] " f.heckenbach@fh-soft.de
2021-10-25 8:03 ` jakub at gcc dot gnu.org
@ 2021-10-25 8:27 ` jakub at gcc dot gnu.org
2023-06-30 14:01 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-25 8:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
--- gcc/cp/call.c.jj 2021-10-21 16:06:42.231940456 +0200
+++ gcc/cp/call.c 2021-10-25 10:20:00.970635564 +0200
@@ -12735,7 +12735,9 @@ set_up_extended_ref_temp (tree decl, tre
/* If the initializer is constant, put it in DECL_INITIAL so we get
static initialization and use in constant expressions. */
- init = maybe_constant_init (expr);
+ init = maybe_constant_init (expr, NULL_TREE,
+ VAR_P (decl)
+ && DECL_DECLARED_CONSTEXPR_P (decl));
/* As in store_init_value. */
init = cp_fully_fold (init);
if (TREE_CONSTANT (init))
makes this accepted, but not the PR101588 testcase.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102921] error: modification of '<temporary>' is not a constant expression
2021-10-24 23:39 [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression f.heckenbach@fh-soft.de
` (2 preceding siblings ...)
2021-10-25 8:27 ` jakub at gcc dot gnu.org
@ 2023-06-30 14:01 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-06-30 14:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Keywords| |rejects-valid
CC| |ppalka at gcc dot gnu.org
Target Milestone|--- |12.3
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Looks like this is fixed for GCC 12.3+ by the fix for PR107079
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-30 14:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 23:39 [Bug c++/102921] New: error: modification of '<temporary>' is not a constant expression f.heckenbach@fh-soft.de
2021-10-24 23:43 ` [Bug c++/102921] " f.heckenbach@fh-soft.de
2021-10-25 8:03 ` jakub at gcc dot gnu.org
2021-10-25 8:27 ` jakub at gcc dot gnu.org
2023-06-30 14:01 ` ppalka at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).