public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101906] New: Constant evaluation failure in concepts
@ 2021-08-14 5:47 de34 at live dot cn
2021-11-03 19:37 ` [Bug c++/101906] " ppalka at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: de34 at live dot cn @ 2021-08-14 5:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906
Bug ID: 101906
Summary: Constant evaluation failure in concepts
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
Following code fails to compile when the macro MAYBE_CWG1581 is not defined.
#include <bit>
#include <cstddef>
namespace test {
template<int> using voidify = void;
template<std::size_t N>
struct obj_rep { unsigned char value[N]; };
template<class T>
concept constant_value_initializable =
requires { typename voidify<(std::bit_cast<obj_rep<sizeof(T)>>(T()), 0)>;
};
}
struct foo {
int x;
};
struct bar {
int x = -1;
};
#ifdef MAYBE_CWG1581
using my_void =
test::voidify<(std::bit_cast<test::obj_rep<sizeof(bar)>>(bar()), 0)>;
#endif
static_assert(test::constant_value_initializable<int>);
static_assert(test::constant_value_initializable<foo>);
static_assert(test::constant_value_initializable<bar>); // It's buggy
static_assert(!test::constant_value_initializable<int*>);
// Correct: std::bit_cast doesn't perform constant evaluation when involving
pointers
int main()
{
}
The godbolt link: https://gcc.godbolt.org/z/6dscsaGTM
It seems that currently gcc fails to generate the definition of
std::bit_cast<SomeType> when determining if the concept is satisfied, while it
can generate such definition when a type alias declaration is encountered.
Maybe related to WG21 P0859R0/CWG1581.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/101906] Constant evaluation failure in concepts
2021-08-14 5:47 [Bug c++/101906] New: Constant evaluation failure in concepts de34 at live dot cn
@ 2021-11-03 19:37 ` ppalka at gcc dot gnu.org
2022-03-24 15:13 ` ppalka at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-03 19:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
CC| |ppalka at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2021-11-03
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced rejects-valid C++20 testcase:
template<int> using voidify = void;
template<class T>
concept constant_value_initializable
= requires { typename voidify<(T(), 0)>; };
struct bar {
int x = -1;
};
static_assert(constant_value_initializable<bar>);
Started with r10-3735 aka the C++20 concepts merge.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/101906] Constant evaluation failure in concepts
2021-08-14 5:47 [Bug c++/101906] New: Constant evaluation failure in concepts de34 at live dot cn
2021-11-03 19:37 ` [Bug c++/101906] " ppalka at gcc dot gnu.org
@ 2022-03-24 15:13 ` ppalka at gcc dot gnu.org
2022-09-12 21:06 ` cvs-commit at gcc dot gnu.org
2022-09-12 21:07 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-24 15:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
FWIW one workaround is to use a class template instead of an alias template,
e.g.
-template<int> using voidify = void;
+template<int> struct voidify {};
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/101906] Constant evaluation failure in concepts
2021-08-14 5:47 [Bug c++/101906] New: Constant evaluation failure in concepts de34 at live dot cn
2021-11-03 19:37 ` [Bug c++/101906] " ppalka at gcc dot gnu.org
2022-03-24 15:13 ` ppalka at gcc dot gnu.org
@ 2022-09-12 21:06 ` cvs-commit at gcc dot gnu.org
2022-09-12 21:07 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-12 21:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906
--- Comment #3 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:c3ba0eaaa223f7b8208d279e3f39ff134912f9e9
commit r13-2633-gc3ba0eaaa223f7b8208d279e3f39ff134912f9e9
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue Jun 7 14:19:53 2022 -0400
c++: template-id arguments are evaluated [PR101906]
Here we're neglecting to clear cp_unevaluated_operand when substituting
into the arguments of the alias template-id 'skip<(T(), 0), T>' with T=A,
which means cp_unevaluated_operand remains set during mark_used for
A::A() and so we don't synthesize it. Later constant evaluation for
the substituted template argument '(A(), 0)' (from coerce_template_parms)
fails with "'constexpr A::A()' used before its definition" since it was
never synthesized.
This doesn't happen with a class template because tsubst_aggr_type
clears cp_unevaluated_operand during substitution thereof. But since
template arguments are generally manifestly constant-evaluated, which in
turn are evaluated even in an unevaluated operand, we should be clearing
cp_unevaluated_operand more broadly whenever substituting into any set
of template arguments. To that end this patch makes us clear it during
tsubst_template_args.
PR c++/101906
gcc/cp/ChangeLog:
* pt.cc (tsubst_template_args): Set cp_evaluated here.
(tsubst_aggr_type): Not here.
gcc/testsuite/ChangeLog:
* g++.dg/template/evaluated1.C: New test.
* g++.dg/template/evaluated1a.C: New test.
* g++.dg/template/evaluated1b.C: New test.
* g++.dg/template/evaluated1c.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/101906] Constant evaluation failure in concepts
2021-08-14 5:47 [Bug c++/101906] New: Constant evaluation failure in concepts de34 at live dot cn
` (2 preceding siblings ...)
2022-09-12 21:06 ` cvs-commit at gcc dot gnu.org
@ 2022-09-12 21:07 ` ppalka at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-09-12 21:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101906
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |13.0
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13, thanks for the bug report.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-12 21:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14 5:47 [Bug c++/101906] New: Constant evaluation failure in concepts de34 at live dot cn
2021-11-03 19:37 ` [Bug c++/101906] " ppalka at gcc dot gnu.org
2022-03-24 15:13 ` ppalka at gcc dot gnu.org
2022-09-12 21:06 ` cvs-commit at gcc dot gnu.org
2022-09-12 21:07 ` 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).