public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112749] New: GCC accepts invalid code in concepts (requires clause incorrectly satisfied)
@ 2023-11-28 18:22 novulae at hotmail dot com
2023-11-28 20:44 ` [Bug c++/112749] " ppalka at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: novulae at hotmail dot com @ 2023-11-28 18:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112749
Bug ID: 112749
Summary: GCC accepts invalid code in concepts (requires clause
incorrectly satisfied)
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: novulae at hotmail dot com
Target Milestone: ---
The below example is ill-formed - the requires clause should not be satisfied
due to the failure to instantiate W1<int>, but GCC accepts the code
nonetheless.
Clang rejects the code.
$ cat gcc-bug.cpp
template<class> concept C1 = true;
template<class T> using W1 = decltype(nonexistent<T>(0));
template<class T>
requires C1<W1<T>>
void func(T);
void test() {
func(0);
}
$ g++ -c -std=c++20 gcc-bug.cpp
$ clang++ -c -std=c++20 gcc-bug.cpp
gcc-bug.cpp:10:3: error: no matching function for call to 'func'
10 | func(0);
| ^~~~
gcc-bug.cpp:7:6: note: candidate template ignored: constraints not satisfied
[with T = int]
7 | void func(T);
| ^
gcc-bug.cpp:3:39: note: because substituted constraint expression is
ill-formed: use of undeclared identifier 'nonexistent'
3 | template<class T> using W1 = decltype(nonexistent<T>(0));
| ^
1 error generated.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/112749] GCC accepts invalid code in concepts (requires clause incorrectly satisfied)
2023-11-28 18:22 [Bug c++/112749] New: GCC accepts invalid code in concepts (requires clause incorrectly satisfied) novulae at hotmail dot com
@ 2023-11-28 20:44 ` ppalka at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-11-28 20:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112749
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
CC| |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the bug report, I think this is pretty much a dup of PR102419.
GCC is behaving correctly here: the normal form of the constraint C1<W1<T>> is
just 'true (with empty parameter mapping)' which is independent of the template
parameter, so the constraint is trivially satisfied for any choice of T. To
get the behavior you desire, define C1 in a way that depends on its template
parameter e.g.
template<class T> concept C1 = requires { typename T; };
*** This bug has been marked as a duplicate of bug 102419 ***
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-28 20:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 18:22 [Bug c++/112749] New: GCC accepts invalid code in concepts (requires clause incorrectly satisfied) novulae at hotmail dot com
2023-11-28 20:44 ` [Bug c++/112749] " 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).