public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104418] New: Error inheriting base class constructors by using-declaration
@ 2022-02-07 11:51 fchelnokov at gmail dot com
2022-02-07 19:21 ` [Bug c++/104418] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-07 11:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
Bug ID: 104418
Summary: Error inheriting base class constructors by
using-declaration
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
This code
```
struct B {
B(int) {}
B(int&&) {}
};
int i = 1;
B b(i); //ok everywhere
struct C : B {
using B::B;
};
C c(i); //ok in Clang only
```
is accepted in Clang, but GCC complains:
```
<source>:13:6: error: use of deleted function 'C::C(int) [inherited from B]'
13 | C c(i);
| ^
<source>:10:14: note: 'C::C(int) [inherited from B]' is implicitly deleted
because the default definition would be ill-formed:
10 | using B::B;
| ^
<source>:10:14: error: call of overloaded 'B(int)' is ambiguous
```
Demo: https://gcc.godbolt.org/z/79EoYM94d
Related question: https://stackoverflow.com/q/71005539/7325599
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
@ 2022-02-07 19:21 ` pinskia at gcc dot gnu.org
2022-02-07 20:43 ` fchelnokov at gmail dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-07 19:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC and ICC reject this for the same reason as GCC. Are you sure this is not a
bug in clang?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
2022-02-07 19:21 ` [Bug c++/104418] " pinskia at gcc dot gnu.org
@ 2022-02-07 20:43 ` fchelnokov at gmail dot com
2022-02-07 21:05 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-07 20:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
--- Comment #2 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
My personal feeling is that if a compiler accepts `B b(i);` then it must accept
`C c(i);` as well because of [namespace.udecl] p13:
> Constructors that are named by a using-declaration are treated as though they were constructors of the derived class when looking up the constructors of the derived class ([class.qual]) or forming a set of overload candidates ([over.match.ctor], [over.match.copy], [over.match.list]).
But probably I miss something.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
2022-02-07 19:21 ` [Bug c++/104418] " pinskia at gcc dot gnu.org
2022-02-07 20:43 ` fchelnokov at gmail dot com
@ 2022-02-07 21:05 ` pinskia at gcc dot gnu.org
2022-02-07 21:24 ` fchelnokov at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-07 21:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
But this is invalid code with a similar error message:
struct B {
B(int) {}
B(int&&) {}
};
struct C : B {
C(int a) : B{(int)a}{}
};
So the question is how is default constructor done, is it done with the cast
causing an rvalue or not?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
` (2 preceding siblings ...)
2022-02-07 21:05 ` pinskia at gcc dot gnu.org
@ 2022-02-07 21:24 ` fchelnokov at gmail dot com
2022-02-08 2:51 ` [Bug c++/104418] [C++14+] " pinskia at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-07 21:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
--- Comment #4 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
I think `using B::B;` is not the same as redefining each constructor with the
explicit call of base class constructor `C(int a) : B{(int)a}{}`.
Please consider this example proving it:
```
struct A {
A() {}
A(const A&) = delete;
};
struct B {
B(A) {}
};
// ok everywhere
struct C : B {
using B::B;
};
//error everywhere
struct D : B {
D(A a) : B(a) {}
};
```
Here struct C definition is fine, but struct D is ill-formed because it
requires A to be copyable. Demo: https://gcc.godbolt.org/z/T7bhv9jeP
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] [C++14+] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
` (3 preceding siblings ...)
2022-02-07 21:24 ` fchelnokov at gmail dot com
@ 2022-02-08 2:51 ` pinskia at gcc dot gnu.org
2022-02-08 2:53 ` [Bug c++/104418] [C++17+] " pinskia at gcc dot gnu.org
2022-02-08 18:55 ` fchelnokov at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-08 2:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Summary|Error inheriting base class |[C++14+] Error inheriting
|constructors by |base class constructors by
|using-declaration |using-declaration
Last reconfirmed| |2022-02-08
Keywords| |rejects-valid
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Fedor Chelnokov from comment #4)
> I think `using B::B;` is not the same as redefining each constructor with
> the explicit call of base class constructor `C(int a) : B{(int)a}{}`.
Sorry I meant it should be done by static_cast<int&&>(a) which is the move
syntax rather than by a copy.
There looks like there are some differences between versions of the C++
standard too.
C++11 (before defect reports) In class.inhctor/8 had:
Each expression in the expression-list is of the form static_cast<T&&>(p),
where p is the name
of the corresponding constructor parameter and T is the declared type of p.
But that was removed it looks like with
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0136r1.html
So the code is invalid C++11 but valid C++14 it seems. clang gets it wrong for
C++11 but gets it correct for C++14+.
GCC gets it wrong for C++14+.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] [C++17+] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
` (4 preceding siblings ...)
2022-02-08 2:51 ` [Bug c++/104418] [C++14+] " pinskia at gcc dot gnu.org
@ 2022-02-08 2:53 ` pinskia at gcc dot gnu.org
2022-02-08 18:55 ` fchelnokov at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-08 2:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[C++14+] Error inheriting |[C++17+] Error inheriting
|base class constructors by |base class constructors by
|using-declaration |using-declaration
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> So the code is invalid C++11 but valid C++14 it seems. clang gets it wrong
> for C++11 but gets it correct for C++14+.
>
> GCC gets it wrong for C++14+.
Or that is part of C++17. Someone else will have to decide there. But clang is
definitely wrong for C++11 and GCC is definitely wrong for C++17 and C++20.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/104418] [C++17+] Error inheriting base class constructors by using-declaration
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
` (5 preceding siblings ...)
2022-02-08 2:53 ` [Bug c++/104418] [C++17+] " pinskia at gcc dot gnu.org
@ 2022-02-08 18:55 ` fchelnokov at gmail dot com
6 siblings, 0 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-08 18:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104418
--- Comment #7 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Thanks. I submitted Clang bug:
https://github.com/llvm/llvm-project/issues/53653
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-02-08 18:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 11:51 [Bug c++/104418] New: Error inheriting base class constructors by using-declaration fchelnokov at gmail dot com
2022-02-07 19:21 ` [Bug c++/104418] " pinskia at gcc dot gnu.org
2022-02-07 20:43 ` fchelnokov at gmail dot com
2022-02-07 21:05 ` pinskia at gcc dot gnu.org
2022-02-07 21:24 ` fchelnokov at gmail dot com
2022-02-08 2:51 ` [Bug c++/104418] [C++14+] " pinskia at gcc dot gnu.org
2022-02-08 2:53 ` [Bug c++/104418] [C++17+] " pinskia at gcc dot gnu.org
2022-02-08 18:55 ` fchelnokov 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).