0

Is it legal to do the following in C++:

const T array[3]{
  **some expression**,
  **another expression**,
  T{ 1 } - array[0] - array[1]
};

In other words: will the 3rd element always be initialized to 1 - **some expression** - **another expression**?

user1146657
  • 194
  • 2
  • 14

1 Answers1

2

initializer list uses left to right evaluation, but it is evaluated before the initialization of array.

will the 3rd element always be initialized to 1 - some expression - another expression?

No, and you have even UB with T{ 1 } - array[0] - array[1].

Jarod42
  • 190,553
  • 13
  • 166
  • 271