<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59865>59865</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            std::optional::emplace() issues compile error for a nested class with a default initializer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mmatrosov
      </td>
    </tr>
</table>

<pre>
    The following perfectly valid code

```
#include <optional>

struct A {
  struct B {
    int trades_count = 0;
 };
  std::optional<B> config;
};

void foo() {
 std::optional<A::B> opt;
    opt.emplace();
}
```

issues the following compilation error:

```
<source>:12:9: error: no matching member function for call to 'emplace'
    opt.emplace();
 ~~~~^~~~~~~
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/optional:914:2: note: candidate template ignored: requirement 'is_constructible_v<A::B>' was not satisfied [with _Args = <>]
        emplace(_Args&&... __args)
 ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/optional:926:2: note: candidate function template not viable: requires at least argument '__il', but no arguments were provided
 emplace(initializer_list<_Up> __il, _Args&&... __args)
        ^
1 error generated.
Compiler returned: 1
```

under clang-15.

See the demo: https://gcc.godbolt.org/z/161onaEnh

If you do any of the following, the code compiles:

* remove `= 0`
* unnest `B` from `A`
* remove declaration of `A::config`

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVUuvqzYQ_jXOZhQEdiDJggXJOZG6bruOjD0QV8ZO_ci55y7y2ysDed2e3nZZhIw8zIP55vMH9171BrEm5Y6Ubwsew8m6ehh4cNbby6K18rP-7YTQWa3thzI9nNF1KIL-hAvXSoKwEkn-RvJmXqt8vqctZcoIHSUCYXt7Dsoargl7f47xwUURoAGy3k0WgNm2e7YBKBMgOC7RH4WNJgB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