Why do Clang and VS2013 accept moving brace-initialized default arguments, but not GCC 4.8 or 4.9?

Update It appears a fix for the problem has been checked in. Interesting question. It definitely seems to be a bug with how GCC handles = {} initialized default arguments, which was a late addition to the standard. The problem can be reproduced with a pretty simple class in place of std::unordered_map<int,int>: #include <utility> struct … Read more

Has the C++17 extension to aggregate initialization made brace initialization dangerous?

struct D and struct E represent two completely unrelated types. But they’re not “completely unrelated” types. They both have the same base class type. This means that every D is implicitly convertible to a B. And therefore every D is a B. So doing E e{d}; is no different from E e{b}; in terms of … Read more

Why can I not brace initialize a struct derived from another struct?

Answer for C++ standard versions before C++17: Your problem has to do with aggregate initialization: struct X is an aggregate while struct Y is not. Here is the standard quote about aggregates (8.5.1): An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equal-initializers for non-static data members (9.2), … Read more

Deleted default constructor. Objects can still be created… sometimes

When viewing things this way it is easy to say there is complete and utter chaos in the way an object is initialized. The big difference comes from the type of foo: if it is an aggregate type or not. It is an aggregate if it has: no user-provided constructors (a deleted or defaulted function … Read more

What does “return {}” statement mean in C++11?

return {}; indicates “return an object of the function’s return type initialized with an empty list-initializer”. The exact behaviour depends on the returned object’s type. From cppreference.com (because the OP is tagged C++11, I excluded the rules in C++14 and C++17; refer to the link for further details): If the braced-init-list is empty and T … Read more

What are the advantages of list initialization (using curly braces)?

Basically copying and pasting from Bjarne Stroustrup’s “The C++ Programming Language 4th Edition”: List initialization does not allow narrowing (§iso.8.5.4). That is: An integer cannot be converted to another integer that cannot hold its value. For example, char to int is allowed, but not int to char. A floating-point value cannot be converted to another … Read more

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