public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94252] New: Can't use a lambda in a requires expression
@ 2020-03-21 17:51 barry.revzin at gmail dot com
2020-03-23 11:38 ` [Bug c++/94252] " julius_huelsmann at freenet dot de
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: barry.revzin at gmail dot com @ 2020-03-21 17:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
Bug ID: 94252
Summary: Can't use a lambda in a requires expression
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
This program:
auto f = []{ return 0; };
static_assert(requires { f(); });
Fails to compile on trunk (https://godbolt.org/z/DEuoVM), with the error:
<source>:2:15: error: static assertion failed
2 | static_assert(requires { f(); });
| ^~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94252] Can't use a lambda in a requires expression
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
@ 2020-03-23 11:38 ` julius_huelsmann at freenet dot de
2020-03-24 18:08 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: julius_huelsmann at freenet dot de @ 2020-03-23 11:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
--- Comment #1 from Julius Hülsmann <julius_huelsmann at freenet dot de> ---
This seems to apply to member functions aswell; the following assertion fails
aswell on gcc-trunk on [compilerExplorer](https://godbolt.org/z/NxgkH5)
struct T { int f(int) noexcept; };
int main() {
static_assert(requires(T o, int i) {
o.f(i);
//{ o.f(i) } noexcept->std::same_as<int>; //< also fails.
});
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94252] Can't use a lambda in a requires expression
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
2020-03-23 11:38 ` [Bug c++/94252] " julius_huelsmann at freenet dot de
@ 2020-03-24 18:08 ` ppalka at gcc dot gnu.org
2020-03-25 4:16 ` ppalka at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-24 18:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |10.0
Known to fail| |10.0
Last reconfirmed| |2020-03-24
Ever confirmed|0 |1
CC| |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |NEW
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94252] Can't use a lambda in a requires expression
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
2020-03-23 11:38 ` [Bug c++/94252] " julius_huelsmann at freenet dot de
2020-03-24 18:08 ` ppalka at gcc dot gnu.org
@ 2020-03-25 4:16 ` ppalka at gcc dot gnu.org
2020-03-28 12:59 ` cvs-commit at gcc dot gnu.org
2020-03-28 13:00 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-25 4:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94252] Can't use a lambda in a requires expression
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
` (2 preceding siblings ...)
2020-03-25 4:16 ` ppalka at gcc dot gnu.org
@ 2020-03-28 12:59 ` cvs-commit at gcc dot gnu.org
2020-03-28 13:00 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-28 12:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
--- 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:a7ea3d2ced786c4544fa625f34f515d89ed074fe
commit r10-7441-ga7ea3d2ced786c4544fa625f34f515d89ed074fe
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Mar 28 08:56:59 2020 -0400
c++: requires-expression outside of a template is misevaluated [PR94252]
This PR shows that a REQUIRES_EXPR outside of a template can sometimes be
misevaluated. This happens because the evaluation routine
tsubst_requires_expr
(and diagnose_requires_expr) assumes the REQUIRES_EXPR's subtrees are
templated
trees and that therefore it's safe to call tsubst_expr on them. But this
assumption isn't valid when we've parsed a REQUIRES_EXPR outside of a
template
context. In order to make this assumption valid here, this patch sets
processing_template_decl to non-zero before parsing the body of a
REQUIRES_EXPR
so that its subtrees are indeed always templated trees.
gcc/cp/ChangeLog:
PR c++/94252
* constraint.cc (tsubst_compound_requirement): Always suppress
errors
from type_deducible_p and expression_convertible_p, as they're not
substitution errors.
(diagnose_atomic_constraint) <case INTEGER_CST>: Remove this case
so
that we diagnose INTEGER_CST expressions of non-bool type via the
default case.
* cp-gimplify.c (cp_genericize_r) <case REQUIRES_EXPR>: New case.
* parser.c (cp_parser_requires_expression): Always parse the
requirement
body as if we're processing a template, by temporarily incrementing
processing_template_decl. Afterwards, if we're not actually in a
template context, perform semantic processing to diagnose any
invalid
types and expressions.
* pt.c (tsubst_copy_and_build) <case REQUIRES_EXPR>: Remove dead
code.
* semantics.c (finish_static_assert): Explain an assertion failure
when the condition is a REQUIRES_EXPR like we do when it is a
concept
check.
gcc/testsuite/ChangeLog:
PR c++/94252
* g++.dg/concepts/diagnostic7.C: New test.
* g++.dg/concepts/pr94252.C: New test.
* g++.dg/cpp2a/concepts-requires18.C: Adjust to expect an
additional
diagnostic.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94252] Can't use a lambda in a requires expression
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
` (3 preceding siblings ...)
2020-03-28 12:59 ` cvs-commit at gcc dot gnu.org
@ 2020-03-28 13:00 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-03-28 13:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94252
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 10.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-28 13:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-21 17:51 [Bug c++/94252] New: Can't use a lambda in a requires expression barry.revzin at gmail dot com
2020-03-23 11:38 ` [Bug c++/94252] " julius_huelsmann at freenet dot de
2020-03-24 18:08 ` ppalka at gcc dot gnu.org
2020-03-25 4:16 ` ppalka at gcc dot gnu.org
2020-03-28 12:59 ` cvs-commit at gcc dot gnu.org
2020-03-28 13:00 ` 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).