C ++ 11 value initialization before aggregate initialization

I am trying to understand @bolov's first accepted answer to the question Remote default constructor. Objects can still be created ... sometimes [1]

I think I found an error there, and so he messed up the whole explanation.

@bolov explains why this SUCCEED code compiles in C ++ 11:

Scenario A

struct foo {
  foo() = delete;
};

// All bellow OK (no errors, no warnings)
foo f = foo{};
foo f = {};
foo f{}; // will use only this from now on.

And why is this FAILS code compiled in C ++ 11:

Script c

struct foo {
  foo() = delete;
  foo(int) {};
};

foo f{}; // error call to deleted constructor

He says that the fact is that the first foo is an aggregate and the second foo is not an aggregate.

Then it produces an excerpt from cppreference:

Effects of initializing a list of an object of type T: ...

  • If T is an aggregate type, aggregate initialization is performed. This applies to ABDE scripts (and F in C ++ 14)
  • Otherwise, the constructors T are considered in two phases:

    • , std:: initializer_list...

    • [...] T [...] C ( F ++ 11)...

, foo f {}; A . . ++ 11 ( # 3337, ) :

- T :

  • , T - , .
  • , T , (8.5.1)

, foo f {}; A , DELETED , .

+4
1

Core Issue 1301, ++ 11, :

- T :

  • , T - , .
  • , T , (8.5.1)

- T :

  • T , (8.5.1)
  • , , T - , .

, foo{} A .

+3

Source: https://habr.com/ru/post/1655157/


All Articles