public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer
@ 2021-06-27 0:21 florin at iucha dot net
2021-06-27 4:24 ` [Bug libstdc++/101227] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: florin at iucha dot net @ 2021-06-27 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227
Bug ID: 101227
Summary: Clang++ fails to instantiate std::optional if nested
type has a non-static data member initializer
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: florin at iucha dot net
Target Milestone: ---
I have reported https://bugs.llvm.org/show_bug.cgi?id=50904 and David suggested
it might be a bug in libstdc++.
GCC11.1 compiles this ok, Clang11 fails:
#include <optional>
class Bar
{
public:
struct Foo
{
int someInt = 3;
};
std::optional<Foo> theFoo;
};
int main()
{
Bar aBar;
aBar.theFoo = std::make_optional<Bar::Foo>();
return 0;
}
---
<source>:18:18: error: no matching function for call to 'make_optional'
aBar.theFoo = std::make_optional<Bar::Foo>();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/optional:1276:5:
note: candidate template ignored: requirement 'is_constructible_v<Bar::Foo>'
was not satisfied [with _Tp = Bar::Foo, _Args = <>]
make_optional(_Args&&... __args)
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/optional:1268:5:
note: candidate function template not viable: requires single argument '__t',
but no arguments were provided
make_optional(_Tp&& __t)
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/optional:1284:5:
note: candidate function template not viable: requires at least argument
'__il', but no arguments were provided
make_optional(initializer_list<_Up> __il, _Args&&... __args)
^
1 error generated.
Compiler returned: 1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/101227] Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer
2021-06-27 0:21 [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer florin at iucha dot net
@ 2021-06-27 4:24 ` pinskia at gcc dot gnu.org
2021-06-27 16:05 ` dblaikie at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-27 4:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang is failing because of "requirement 'is_constructible_v<Bar::Foo>' was not
satisfied [with _Tp = Bar::Foo, _Args = <>]"
But it seems like it should be true.
from https://en.cppreference.com/w/cpp/types/is_constructible:
"If T is an object or reference type and the variable definition T
obj(std::declval<Args>()...); is well-formed, provides the member constant
value equal to true. In all other cases, value is false.
For the purposes of this check, the variable definition is never interpreted as
a function declaration, and the use of std::declval is not considered an
odr-use. "
So the question becomes why is std::is_constructible<Bar::Foo>::value is false.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/101227] Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer
2021-06-27 0:21 [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer florin at iucha dot net
2021-06-27 4:24 ` [Bug libstdc++/101227] " pinskia at gcc dot gnu.org
@ 2021-06-27 16:05 ` dblaikie at gmail dot com
2021-06-28 9:05 ` redi at gcc dot gnu.org
2021-11-22 10:56 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: dblaikie at gmail dot com @ 2021-06-27 16:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227
David Blaikie <dblaikie at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dblaikie at gmail dot com
--- Comment #2 from David Blaikie <dblaikie at gmail dot com> ---
My guess, libstdc++'s std::optional uses is_default_constructible
unconditionally in some way, instantiating the template while the type
parameter is incomplete (because the nested class is incomplete until the
enclosing class is complete?).
Essentially something like this:
https://godbolt.org/z/6eohMofdb
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/101227] Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer
2021-06-27 0:21 [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer florin at iucha dot net
2021-06-27 4:24 ` [Bug libstdc++/101227] " pinskia at gcc dot gnu.org
2021-06-27 16:05 ` dblaikie at gmail dot com
@ 2021-06-28 9:05 ` redi at gcc dot gnu.org
2021-11-22 10:56 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-28 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes. It's basically the same issue as PR 96645. Nested types and default member
initializers are not compatible with standard library wrapper types. Yet
another horrible corner of C++.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/101227] Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer
2021-06-27 0:21 [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer florin at iucha dot net
` (2 preceding siblings ...)
2021-06-28 9:05 ` redi at gcc dot gnu.org
@ 2021-11-22 10:56 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-22 10:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101227
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-11-22
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-22 10:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 0:21 [Bug libstdc++/101227] New: Clang++ fails to instantiate std::optional if nested type has a non-static data member initializer florin at iucha dot net
2021-06-27 4:24 ` [Bug libstdc++/101227] " pinskia at gcc dot gnu.org
2021-06-27 16:05 ` dblaikie at gmail dot com
2021-06-28 9:05 ` redi at gcc dot gnu.org
2021-11-22 10:56 ` 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).