Is double-braced scalar initialization allowed by the C++ standard?

This is ill-formed. gcc is wrong to accept it and clang seems to allow it as an extension, as it warns about it.

I’m going to quote the latest draft, but it doesn’t make a difference. List initialization works as follows as per [dcl.init.list], where T is int in this case:

  • If the initializer list is a designated initializer list, […] => it’s not
  • If T is an aggregate class […] => it’s not
  • If T is a character array […] => it’s not.
  • If T is an aggregate […] => it’s not (only arrays and classes can be aggregates)
  • If the initializer list has no elements […] => it doesn’t
  • If T is a specialization of std::initializer_list […] => it’s not
  • If T is a class type […] => it’s not
  • If T is an enumeration with fixed underlying type […] => it’s not
  • If the initializer list has a single element of type E […] => a braced initializer list has no type, so no
  • If T is a reference type […] => it isn’t
  • If the initializer list has no elements […] => it doesn’t
  • Otherwise the program is ill-formed

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)