Consider this code:
struct S
{
int x;
double y = 1.1;
};
int main()
{
S s = {0};
}
According to the C++14 standard, § 8.5.1/7
If there are fewer initializer-clauses in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized from its brace-or-equal-initializer or, if there is no brace-or-equal- initializer, from an empty initializer list (8.5.4).
the code should be perfectly valid.
However, g++ 4.9.2 rejects the code (compiled with -std=c++14
)
so.cpp:9:13: error: could not convert '{0}' from '<brace-enclosed initializer list>' to 'S'
S s = {0};
clang++ on the other hand compiles it.
Is this a known issue for g++?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…