When using a braced-init-list containing multiple braced-init-list, what are the rules defined by the standard for B, C, and D?
For B, I believe this scenario is defined within the standard as a braced-init-list with a single element and therefore it calls Test(int) directly with no temporary - but I am unable to find where.
For C and D, I am unsure of whether this is undefined behavior or not.
I am also interested in what occurs when using more than a single element i.e. {{{1, 2}}} and if this changes the behavior for B, C, or D?
#include <iostream>
struct Test {
Test(const int a) {
// A and B call this
}
Test(Test&& test) = delete;
Test(const Test& test) = delete;
};
int main()
{
Test a{1}; // calls Test(int)
Test b{{2}}; // B
Test c{{{3}}}; // C
Test d{{{{4}}}}; // D
// Test e{a}; error, deleted copy constructor
// Test f{Test{0}}; error, deleted move constructor
return 0;
}
GCC g++ my_prog.cpp gives me an error for C and D only:
my_prog.cpp: In function 'int main()':
my_prog.cpp:16:17: error: too many braces around initializer for 'int' [-fpermissive]
Test c{{{3}}};
^
my_prog.cpp:4:14: note: initializing argument 1 of 'Test::Test(int)'
Test(int a) {
~~~~^