Consider this example:
#include <vector>
#include <stdexcept>
struct A
{
float a;
float b;
float c;
float d;
};
struct B
{
A a;
std::vector<int> b;
};
int main() {
B b{};
if (b.a.a || b.a.b || b.a.c || b.a.d) throw std::runtime_error("Compiler bug?");
}
If I understand correctly, according to https://en.cppreference.com/w/cpp/language/zero_initialization, it cannot throw because zero initialization should be performed for B::a as it should for "members of value-initialized class types that have no constructors".
If it throws, is it a compiler bug or am I missing something?
[edit]
Here with clang 10 and optimization enabled it just does "mov eax, 2" and "ret" (meaning the condition is false): https://godbolt.org/z/CXrc3G
But if I remove the braces, it does "mov eax, 1" and "ret" (meaning the condition is true). But here I think it can return whatever it want because it's just UB. https://godbolt.org/z/tBvLzZ
So it seems clang thinks that with braces zero initialization must be performed.
Edit: I submitted a bug on intel's website: https://community.intel.com/t5/Intel-C-Compiler/Aggregate-initialization-bug-with-nested-struct/td-p/1178228
An intel person replied "I've reported this issue to our Developer." Poor developer, single-handedly supporting all icc development.