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

    <tr>
        <th>Summary</th>
        <td>
            clang-16: Incorrect "must explicitly initialize the member" error in function-local class
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    See https://godbolt.org/z/zoxs4nae4 for a self-contained example.
Both gcc and clang-15 accept the code. clang-16 and clang-trunk reject it.

For

```
#include<memory>

class TypeErased {
 public:
    virtual ~TypeErased();
};

template <typename T, typename... Args>
std::unique_ptr<TypeErased> make_type_erased(Args&&... args) {
   struct TypeErasureWrapper : public TypeErased {
      T content;
      TypeErasureWrapper(Args&&... args) : content{std::forward<Args>(args)...} {}
      ~TypeErasureWrapper() override {}
   };

   return std::make_unique<TypeErasureWrapper>(std::forward<Args>(args)...);
}

class NoDefaultConstructor {
    public:
 NoDefaultConstructor(int);
};


auto testNoDefaultConstructor() {
    return make_type_erased<NoDefaultConstructor>(1);
}
```

The error message from clang-16 does not make sense to me:

```
<source>:12:7: error: constructor for 'TypeErasureWrapper' must explicitly initialize the member 'content' which does not have a default constructor
 TypeErasureWrapper(Args&&... args) : content{std::forward<Args>(args)...} {}
      ^                                 ^
```

clang is complaining that we would not initialize `content`, but on the very same line we are actually initializing it.

The error does not occur if the class has a default constructor or if I define `TypeErasureWrapper` outside the function, as shown in https://godbolt.org/z/YYzhWPnKx
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVkuP4jgX_TVmc1VRYocEFiwoKKTWJ30aaUpq9aplnJvE046d8QOKWvRvH9k8h6Ifu4mqDMa5j3Pu8bW5c7LTiAsyfSbT9YQH3xu72JkOlevQcd1NtqY5LP5EhN770RG2JHRD6KYzzdYonxnbEbp5j__mzZ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