This is not copy-initializing, or is it?

前端 未结 1 694
误落风尘
误落风尘 2021-01-02 15:45

In the following code I am not allowed to declare an explicit ctor because the compiler says I am using it in a copy-initializing context (clang 3.3 and gc

相关标签:
1条回答
  • 2021-01-02 16:10

    The = notation should not affect the complaint because reference binding doesn't behave differently whether expressed by direct- or copy-initialization. What's being initialized here is the return value object, which does not have its own name.

    Unfortunately, GCC is right to complain, as does Clang. According to §6.6.3/2 [stmt.return],

    A return statement with a braced-init-list initializes the object or reference to be returned from the function by copy-list-initialization (8.5.4) from the specified initializer list.

    So, there is an invisible = sign there and you can't get around it.

    0 讨论(0)
提交回复
热议问题