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

Reply via email to