1

See this godbolt:

struct Foo
{
    Foo() noexcept = default;
    int t{};
};

struct Bar
{
    Foo baz{};
};

int main()
{
    return Bar
    {
        .baz = Foo{}
    }.baz.t;
}

When deleting noexcept, code for the constructor is auto-generated as expected. What gives?

user17732522
  • 53,019
  • 2
  • 56
  • 105
JanKXSKI
  • 21
  • 2
  • What do you mean with "_auto-generated_"? What specifically in the godbolt link do you consider unexpected? – user17732522 May 04 '23 at 17:13
  • 1
    The above program won't link because the called symbol `Foo::Foo(void)` is missing! When deleting `noexcept`, the program successfully links because the compiler generates code for Foo's constructor. – JanKXSKI May 04 '23 at 17:19
  • Ah ok, I didn't notice that. Looks like a bug in MSVC to me. – user17732522 May 04 '23 at 17:23
  • I thought I might have missed something with the noexcept, but I think so too. Thanks for having a look! I will report to Microsoft. – JanKXSKI May 04 '23 at 17:43
  • 1
    My guess would be it'll only generate the constructor when it is actually used and the compiler doesn't realise that it is being used in the initialiser – Alan Birtles May 04 '23 at 18:09

0 Answers0