public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
@ 2021-12-31 15:33 hewillk at gmail dot com
2021-12-31 22:10 ` [Bug libstdc++/103879] " pinskia at gcc dot gnu.org
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: hewillk at gmail dot com @ 2021-12-31 15:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
Bug ID: 103879
Summary: error: accessing value of variant::_Copy_ctor_base
through a 'const variant<string>' glvalue in a
constant expression
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
From
https://stackoverflow.com/questions/70541636/stdvariant-of-stdstring-inside-any-class-in-constexpr-context-fails-to-compi
#include <string>
#include <variant>
struct S {
std::variant<std::string> v;
};
constexpr int func() {
S s{"str"};
return 0;
}
constexpr int x = func();
I think this should be well-formed.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
@ 2021-12-31 22:10 ` pinskia at gcc dot gnu.org
2021-12-31 22:10 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-31 22:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang rejects it also (with their libc++):
<source>:10:5: error: variable of non-literal type 'S' cannot be defined in a
constexpr function
S s{"str"};
^
<source>:6:29: note: 'S' is not literal because it has data member 'v' of
non-literal type 'std::variant<std::string>' (aka 'variant<basic_string<char,
char_traits<char>, allocator<char>>>')
std::variant<std::string> v;
^
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
2021-12-31 22:10 ` [Bug libstdc++/103879] " pinskia at gcc dot gnu.org
@ 2021-12-31 22:10 ` pinskia at gcc dot gnu.org
2021-12-31 23:44 ` lhlaurini at hotmail dot com
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-31 22:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC also rejects it:
example.cpp
<source>(14): error C2131: expression did not evaluate to a constant
<source>(10): note: failure was caused by call of undefined function or one not
declared 'constexpr'
<source>(10): note: see usage of 'S::~S'
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
2021-12-31 22:10 ` [Bug libstdc++/103879] " pinskia at gcc dot gnu.org
2021-12-31 22:10 ` pinskia at gcc dot gnu.org
@ 2021-12-31 23:44 ` lhlaurini at hotmail dot com
2022-01-01 16:45 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: lhlaurini at hotmail dot com @ 2021-12-31 23:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
Luiz Henrique Laurini <lhlaurini at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lhlaurini at hotmail dot com
--- Comment #3 from Luiz Henrique Laurini <lhlaurini at hotmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> MSVC also rejects it:
> example.cpp
> <source>(14): error C2131: expression did not evaluate to a constant
> <source>(10): note: failure was caused by call of undefined function or one
> not declared 'constexpr'
> <source>(10): note: see usage of 'S::~S'
It does compile with MSVC v19.latest: https://godbolt.org/z/McKjfdP5Y.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (2 preceding siblings ...)
2021-12-31 23:44 ` lhlaurini at hotmail dot com
@ 2022-01-01 16:45 ` redi at gcc dot gnu.org
2022-01-04 4:57 ` ppalka at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-01 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> clang rejects it also (with their libc++):
Libc++ doesn't support constexpr std::string, and I think it's missing some DRs
to std::variant as well. So I wouldn't use it to confirm anything like this.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (3 preceding siblings ...)
2022-01-01 16:45 ` redi at gcc dot gnu.org
@ 2022-01-04 4:57 ` ppalka at gcc dot gnu.org
2022-01-04 14:13 ` [Bug c++/103879] " ppalka at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-04 4:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |ppalka at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2022-01-04
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Looks like this is a frontend bug, the constexpr engine can't resolve the
indirection (where the D.NNNNN correspond to base class subobjects, the
innermost of which is the _Variant_storage base)
*(struct variant *) &s.v.D.47079.D.46560.D.46478.D.46346.D.46232.D.46136
into just
s.v
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (4 preceding siblings ...)
2022-01-04 4:57 ` ppalka at gcc dot gnu.org
@ 2022-01-04 14:13 ` ppalka at gcc dot gnu.org
2022-01-05 16:20 ` hewillk at gmail dot com
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-04 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced C++14 rejects-valid testcase:
struct A {
int n = 42;
};
struct B : A { };
struct C {
B b;
};
constexpr int f() {
C c;
A& a = static_cast<A&>(c.b);
B& b = static_cast<B&>(a);
return b.n;
}
static_assert(f() == 42, "");
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (5 preceding siblings ...)
2022-01-04 14:13 ` [Bug c++/103879] " ppalka at gcc dot gnu.org
@ 2022-01-05 16:20 ` hewillk at gmail dot com
2022-01-05 16:23 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: hewillk at gmail dot com @ 2022-01-05 16:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #7 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to Patrick Palka from comment #6)
> Reduced C++14 rejects-valid testcase:
>
> struct A {
> int n = 42;
> };
>
> struct B : A { };
>
> struct C {
> B b;
> };
>
> constexpr int f() {
> C c;
> A& a = static_cast<A&>(c.b);
> B& b = static_cast<B&>(a);
> return b.n;
> }
>
> static_assert(f() == 42, "");
Is this the same issue?
#include <string>
#include <ranges>
int main() {
using namespace std::string_literals;
static_assert(std::ranges::distance(
std::views::iota(0, 2) | std::ranges::views::transform([](int) { return
""s; })
| std::ranges::views::join));
}
https://godbolt.org/z/8nve43zvW
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (6 preceding siblings ...)
2022-01-05 16:20 ` hewillk at gmail dot com
@ 2022-01-05 16:23 ` redi at gcc dot gnu.org
2022-01-05 18:53 ` ppalka at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-05 16:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, looks like it.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (7 preceding siblings ...)
2022-01-05 16:23 ` redi at gcc dot gnu.org
@ 2022-01-05 18:53 ` ppalka at gcc dot gnu.org
2022-01-06 1:57 ` hewillk at gmail dot com
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-05 18:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
That one unfortunately seems to be an unrelated constexpr bug. Mind opening a
separate PR?
I'm reducing the testcase..
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (8 preceding siblings ...)
2022-01-05 18:53 ` ppalka at gcc dot gnu.org
@ 2022-01-06 1:57 ` hewillk at gmail dot com
2022-01-10 19:59 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: hewillk at gmail dot com @ 2022-01-06 1:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #10 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to Patrick Palka from comment #9)
> That one unfortunately seems to be an unrelated constexpr bug. Mind opening
> a separate PR?
>
> I'm reducing the testcase..
Reported PR103924.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (9 preceding siblings ...)
2022-01-06 1:57 ` hewillk at gmail dot com
@ 2022-01-10 19:59 ` cvs-commit at gcc dot gnu.org
2022-01-10 20:01 ` ppalka at gcc dot gnu.org
2022-10-05 23:20 ` pinskia at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-10 19:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:ab36b554bd90e8db279d13b133369118814f13fb
commit r12-6425-gab36b554bd90e8db279d13b133369118814f13fb
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Jan 10 14:57:54 2022 -0500
c++: constexpr base-to-derived conversion with offset 0 [PR103879]
r12-136 made us canonicalize an object/offset pair with negative offset
into one with a nonnegative offset, by iteratively absorbing the
innermost component into the offset and stopping as soon as the offset
becomes nonnegative.
This patch strengthens this transformation by making it keep on absorbing
even if the offset is already 0 as long as the innermost component is at
position 0 (and thus absorbing doesn't change the offset). This lets us
accept the two constexpr testcases below, which we'd previously reject
essentially because cxx_fold_indirect_ref would be unable to resolve
*(B*)&b.D123 (where D123 is the base A subobject at position 0) to just b.
PR c++/103879
gcc/cp/ChangeLog:
* constexpr.c (cxx_fold_indirect_ref): Split out object/offset
canonicalization step into a local lambda. Strengthen it to
absorb more components at position 0. Use it before both calls
to cxx_fold_indirect_ref_1.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-base2.C: New test.
* g++.dg/cpp1y/constexpr-base2a.C: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (10 preceding siblings ...)
2022-01-10 19:59 ` cvs-commit at gcc dot gnu.org
@ 2022-01-10 20:01 ` ppalka at gcc dot gnu.org
2022-10-05 23:20 ` pinskia at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-10 20:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |12.0
--- Comment #12 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/103879] error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
` (11 preceding siblings ...)
2022-01-10 20:01 ` ppalka at gcc dot gnu.org
@ 2022-10-05 23:20 ` pinskia at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-05 23:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103879
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |petr.azmanov at wartsila dot com
--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107165 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2022-10-05 23:20 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-31 15:33 [Bug libstdc++/103879] New: error: accessing value of variant::_Copy_ctor_base through a 'const variant<string>' glvalue in a constant expression hewillk at gmail dot com
2021-12-31 22:10 ` [Bug libstdc++/103879] " pinskia at gcc dot gnu.org
2021-12-31 22:10 ` pinskia at gcc dot gnu.org
2021-12-31 23:44 ` lhlaurini at hotmail dot com
2022-01-01 16:45 ` redi at gcc dot gnu.org
2022-01-04 4:57 ` ppalka at gcc dot gnu.org
2022-01-04 14:13 ` [Bug c++/103879] " ppalka at gcc dot gnu.org
2022-01-05 16:20 ` hewillk at gmail dot com
2022-01-05 16:23 ` redi at gcc dot gnu.org
2022-01-05 18:53 ` ppalka at gcc dot gnu.org
2022-01-06 1:57 ` hewillk at gmail dot com
2022-01-10 19:59 ` cvs-commit at gcc dot gnu.org
2022-01-10 20:01 ` ppalka at gcc dot gnu.org
2022-10-05 23:20 ` pinskia 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).