public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114903] New: constraint of CTAD alias deduction guide is evaluated on a wrong type
@ 2024-05-01 8:06 hokein.wu at gmail dot com
2024-05-13 13:53 ` [Bug c++/114903] " cvs-commit at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: hokein.wu at gmail dot com @ 2024-05-01 8:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114903
Bug ID: 114903
Summary: constraint of CTAD alias deduction guide is evaluated
on a wrong type
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hokein.wu at gmail dot com
Target Milestone: ---
See the following example of nested templates:
```
#include <type_traits>
template <typename T>
struct Key {
Key(int);
};
class Forward {};
template <typename T>
constexpr bool C =
std::is_same<T, Forward>(); // changing `Forward` to `double` will make the
following static_assert passed.
template <typename Z>
struct Outer {
template <typename U>
struct Foo {
Foo(U);
U u;
};
template <typename V>
requires(C<Z>)
Foo(V) -> Foo<int>;
};
template <typename Y>
struct T {
template <typename Y2>
struct T2 {
template <typename K>
using AFoo = Outer<Y2>::template Foo<K>;
};
};
T<Forward>::T2<Forward>::AFoo a{1.0}; // the explict deduction guide should be
choosen, Foo<int>
static_assert(std::is_same<decltype(a), Outer<Forward>::Foo<int>>()); // expect
to be true!
```
The constraint `C` in the alias deduction guide should be true, as it is
evaluated on type `Forward`, but gcc seems to evaluate it on `double`.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/114903] constraint of CTAD alias deduction guide is evaluated on a wrong type
2024-05-01 8:06 [Bug c++/114903] New: constraint of CTAD alias deduction guide is evaluated on a wrong type hokein.wu at gmail dot com
@ 2024-05-13 13:53 ` cvs-commit at gcc dot gnu.org
2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
2024-05-13 15:41 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-13 13:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114903
--- Comment #1 from GCC 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:6d31a370e26eeb950c326332633b3e8e84b6630b
commit r15-434-g6d31a370e26eeb950c326332633b3e8e84b6630b
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon May 13 09:53:40 2024 -0400
c++: nested aggregate/alias CTAD fixes [PR114974, PR114901, PR114903]
During maybe_aggr_guide with a nested class template and paren init,
like with list init we need to consider the generic template type rather
than the partially instantiated type since partial instantiations don't
have (partially instantiated) TYPE_FIELDS. In turn we need to partially
substitute PARMs in the paren init case as well. As a drive-by improvement
it seems better to use outer_template_args instead of DECL_TI_ARGS during
this partial substitution so that we lower instead of substitute the
innermost template parameters, which is generally more robust.
And during alias_ctad_tweaks with a nested class template, even though
the guides may be already partially instantiated we still need to
substitute the outermost arguments into its constraints.
PR c++/114974
PR c++/114901
PR c++/114903
gcc/cp/ChangeLog:
* pt.cc (maybe_aggr_guide): Fix obtaining TYPE_FIELDS in
the paren init case. Hoist out partial substitution logic
to apply to the paren init case as well.
(alias_ctad_tweaks): Substitute outer template arguments into
a guide's constraints.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/class-deduction-aggr14.C: New test.
* g++.dg/cpp2a/class-deduction-alias20.C: New test.
* g++.dg/cpp2a/class-deduction-alias21.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/114903] constraint of CTAD alias deduction guide is evaluated on a wrong type
2024-05-01 8:06 [Bug c++/114903] New: constraint of CTAD alias deduction guide is evaluated on a wrong type hokein.wu at gmail dot com
2024-05-13 13:53 ` [Bug c++/114903] " cvs-commit at gcc dot gnu.org
@ 2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
2024-05-13 15:41 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-13 15:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114903
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:57cd8665fea4c339369a43be017583621aa82fed
commit r14-10201-g57cd8665fea4c339369a43be017583621aa82fed
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon May 13 09:53:40 2024 -0400
c++: nested aggregate/alias CTAD fixes [PR114974, PR114901, PR114903]
During maybe_aggr_guide with a nested class template and paren init,
like with list init we need to consider the generic template type rather
than the partially instantiated type since partial instantiations don't
have (partially instantiated) TYPE_FIELDS. In turn we need to partially
substitute PARMs in the paren init case as well. As a drive-by improvement
it seems better to use outer_template_args instead of DECL_TI_ARGS during
this partial substitution so that we lower instead of substitute the
innermost template parameters, which is generally more robust.
And during alias_ctad_tweaks with a nested class template, even though
the guides may be already partially instantiated we still need to
substitute the outermost arguments into its constraints.
PR c++/114974
PR c++/114901
PR c++/114903
gcc/cp/ChangeLog:
* pt.cc (maybe_aggr_guide): Fix obtaining TYPE_FIELDS in
the paren init case. Hoist out partial substitution logic
to apply to the paren init case as well.
(alias_ctad_tweaks): Substitute outer template arguments into
a guide's constraints.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/class-deduction-aggr14.C: New test.
* g++.dg/cpp2a/class-deduction-alias20.C: New test.
* g++.dg/cpp2a/class-deduction-alias21.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 6d31a370e26eeb950c326332633b3e8e84b6630b)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/114903] constraint of CTAD alias deduction guide is evaluated on a wrong type
2024-05-01 8:06 [Bug c++/114903] New: constraint of CTAD alias deduction guide is evaluated on a wrong type hokein.wu at gmail dot com
2024-05-13 13:53 ` [Bug c++/114903] " cvs-commit at gcc dot gnu.org
2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
@ 2024-05-13 15:41 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-05-13 15:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114903
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |RESOLVED
Target Milestone|--- |14.2
CC| |ppalka at gcc dot gnu.org
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14.2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-13 15:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-01 8:06 [Bug c++/114903] New: constraint of CTAD alias deduction guide is evaluated on a wrong type hokein.wu at gmail dot com
2024-05-13 13:53 ` [Bug c++/114903] " cvs-commit at gcc dot gnu.org
2024-05-13 15:39 ` cvs-commit at gcc dot gnu.org
2024-05-13 15:41 ` 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).