public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108683] New: Move Occurs when initializing an aggregate base
@ 2023-02-06 13:08 davidledger at live dot com.au
2023-02-06 14:20 ` [Bug c++/108683] " redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: davidledger at live dot com.au @ 2023-02-06 13:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108683
Bug ID: 108683
Summary: Move Occurs when initializing an aggregate base
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: davidledger at live dot com.au
Target Milestone: ---
```CPP
struct Bar
{
Bar() = delete;
Bar(Bar const &) = delete;
Bar& operator=(Bar const&) = delete;
Bar(Bar&&) = delete;
Bar& operator=(Bar&&) = delete;
explicit Bar(int value) : m_value(value) {}
int m_value;
};
namespace A
{
struct Foo : Bar{}; // this is the only difference.
Bar MakeBar()
{
return Bar(10);
}
}
namespace B
{
struct Foo
{
Bar bar; // this is the only difference.
};
Bar MakeBar()
{
return Bar(10);
}
}
int main()
{
A::Foo foo{ A::MakeBar() };
B::Foo bar{ B::MakeBar() };
}
```
The above example, while failing similarly in clang and GCC. Compiles without
issue on MSVC.
As of C++17:
> An aggregate class or array may include non-aggregate public bases (since C++17), members, or elements, which are initialized as described above (e.g. copy-initialization from the corresponding initializer clause).
cppreference.
So we have an aggregate here. When using GCC, the following error is presented:
```
<source>: In function 'int main()':
<source>:38:30: error: use of deleted function 'Bar::Bar(Bar&&)'
38 | A::Foo foo{ A::MakeBar() };
| ^
<source>:6:5: note: declared here
6 | Bar(Bar&&) = delete;
| ^~~
Compiler returned: 1
```
I believe this should compile without requiring a move constructor of the base
type.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/108683] Move Occurs when initializing an aggregate base
2023-02-06 13:08 [Bug c++/108683] New: Move Occurs when initializing an aggregate base davidledger at live dot com.au
@ 2023-02-06 14:20 ` redi at gcc dot gnu.org
2023-02-06 15:10 ` davidledger at live dot com.au
2023-02-06 15:38 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-06 14:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108683
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Mandatory copy elision isn't possible into an empty base class, so a move needs
to happen.
See PR 98995
*** This bug has been marked as a duplicate of bug 98995 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/108683] Move Occurs when initializing an aggregate base
2023-02-06 13:08 [Bug c++/108683] New: Move Occurs when initializing an aggregate base davidledger at live dot com.au
2023-02-06 14:20 ` [Bug c++/108683] " redi at gcc dot gnu.org
@ 2023-02-06 15:10 ` davidledger at live dot com.au
2023-02-06 15:38 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: davidledger at live dot com.au @ 2023-02-06 15:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108683
--- Comment #2 from David Ledger <davidledger at live dot com.au> ---
Bar stores an int, it isn't empty.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/108683] Move Occurs when initializing an aggregate base
2023-02-06 13:08 [Bug c++/108683] New: Move Occurs when initializing an aggregate base davidledger at live dot com.au
2023-02-06 14:20 ` [Bug c++/108683] " redi at gcc dot gnu.org
2023-02-06 15:10 ` davidledger at live dot com.au
@ 2023-02-06 15:38 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-06 15:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108683
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Pretend I didn't say empty then :)
I think the problem is for any potentially overlapping subobject, which
includes bases. Empty or not.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-06 15:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-06 13:08 [Bug c++/108683] New: Move Occurs when initializing an aggregate base davidledger at live dot com.au
2023-02-06 14:20 ` [Bug c++/108683] " redi at gcc dot gnu.org
2023-02-06 15:10 ` davidledger at live dot com.au
2023-02-06 15:38 ` redi 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).