public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work
@ 2023-05-22 19:55 oleksandr.koval.dev at gmail dot com
2023-05-22 19:59 ` [Bug c++/109935] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: oleksandr.koval.dev at gmail dot com @ 2023-05-22 19:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
Bug ID: 109935
Summary: CTAD for an aggregate with a dependent base class
doesn't work
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: oleksandr.koval.dev at gmail dot com
Target Milestone: ---
https://godbolt.org/z/s9cM719n3
```cpp
template <typename T>
struct B {
T x;
};
template <typename T>
struct C : public B<T> {
};
void f(){
B{1}; // works as expected
C{{1}}; // error
}
```
Not 100% sure about it but I see no reason for `C{{1}}` not to work. Extra set
of braces is required because B<T> is a dependent base class and brace elision
doesn't work for it (https://eel.is/c++draft/over.match.class.deduct#1.5.1).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109935] CTAD for an aggregate with a dependent base class doesn't work
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
@ 2023-05-22 19:59 ` pinskia at gcc dot gnu.org
2023-05-22 20:02 ` oleksandr.koval.dev at gmail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-22 19:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC rejects `C{{1}}` for the same reason as GCC.
clang rejects even `B{1}` .....
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109935] CTAD for an aggregate with a dependent base class doesn't work
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
2023-05-22 19:59 ` [Bug c++/109935] " pinskia at gcc dot gnu.org
@ 2023-05-22 20:02 ` oleksandr.koval.dev at gmail dot com
2023-05-22 20:40 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: oleksandr.koval.dev at gmail dot com @ 2023-05-22 20:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
--- Comment #2 from Oleksandr Koval <oleksandr.koval.dev at gmail dot com> ---
According to cppreference, Clang has not implemented CTAD for aggregates at all
so no surprise here. I know that gcc/msvc rejects it but I don't understand
why.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109935] CTAD for an aggregate with a dependent base class doesn't work
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
2023-05-22 19:59 ` [Bug c++/109935] " pinskia at gcc dot gnu.org
2023-05-22 20:02 ` oleksandr.koval.dev at gmail dot com
@ 2023-05-22 20:40 ` pinskia at gcc dot gnu.org
2023-05-22 20:41 ` pinskia at gcc dot gnu.org
2023-05-23 10:30 ` oleksandr.koval.dev at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-22 20:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
C{B{1}};
Does work though.
I suspect the issue is cannot figure out that {1} can be bound to B<T> and
deudce T there and even GCC gives that as a reason:
<source>:7:8: note: candidate: 'template<class T> C(B<T>)-> C<T>'
7 | struct C : public B<T> {
| ^
<source>:7:8: note: template argument deduction/substitution failed:
<source>:15:10: note: couldn't deduce template parameter 'T'
15 | C{{1}};
| ^
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109935] CTAD for an aggregate with a dependent base class doesn't work
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
` (2 preceding siblings ...)
2023-05-22 20:40 ` pinskia at gcc dot gnu.org
@ 2023-05-22 20:41 ` pinskia at gcc dot gnu.org
2023-05-23 10:30 ` oleksandr.koval.dev at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-22 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The same is true even with a depedent field rather than base:
```
template <typename T>
struct C {
B<T> b;
};
```
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109935] CTAD for an aggregate with a dependent base class doesn't work
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
` (3 preceding siblings ...)
2023-05-22 20:41 ` pinskia at gcc dot gnu.org
@ 2023-05-23 10:30 ` oleksandr.koval.dev at gmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: oleksandr.koval.dev at gmail dot com @ 2023-05-23 10:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109935
--- Comment #5 from Oleksandr Koval <oleksandr.koval.dev at gmail dot com> ---
Right, my understanding is that it should generate hypothetical constructor
like:
```cpp
template <typename T>
struct C : public B<T> {
C(B<T>);
};
```
and it doesn't work with braced-initializer list like in this example:
```cpp
template<typename T>
void test(B<T>){}
B{1}; // ok
test({1}); // error
```
So maybe it should not work by the current rules. I came up with this example
while reading https://wg21.link/P2582R1 (CTAD for inherited ctor-s) which makes
this possible:
```cpp
template<typename T>
struct S1{
S1(T){}
};
template<typename T>
struct S2 : S1<T>{
using S1<T>::S1;
};
S2{1}; // OK, deduced S2<int>
```
It's unfortunate that it doesn't work when we remove explicit constructors so
I'm trying to understand whether it's not allowed by current language rules or
just is not implemented by compilers.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-23 10:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-22 19:55 [Bug c++/109935] New: CTAD for an aggregate with a dependent base class doesn't work oleksandr.koval.dev at gmail dot com
2023-05-22 19:59 ` [Bug c++/109935] " pinskia at gcc dot gnu.org
2023-05-22 20:02 ` oleksandr.koval.dev at gmail dot com
2023-05-22 20:40 ` pinskia at gcc dot gnu.org
2023-05-22 20:41 ` pinskia at gcc dot gnu.org
2023-05-23 10:30 ` oleksandr.koval.dev at gmail dot com
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).