Hello,
The struct below is not initialized when using brace-initialization. This seems to be the same issue as reported here https://community.intel.com/t5/Intel-C-Compiler/Aggregate-initialization-bug-with-nested-struct/m-p/1271801. The members a through d should be initialized as int{} to 0. I assume it's related to the non-default constructor of Q, the values are uninitialized also with an std::vector member as in the linked post. The struct seems to be correctly zero initialized if there are no user-provided constructors.
Compiler version
cl6x --help TMS320C6x C/C++ Compiler v8.3.10 Tools Copyright (c) 1996-2018 Texas Instruments Incorporated
Compilation flags. Observed at O1/2/3
-qq -mv6600 --relaxed_ansi --define=SOC_TDA3XX --keep_unneeded_statics --diag_wrap=off --display_error_number --diag_suppress=556 --diag_suppress=2458 --mem_model:data=far --wchar_t=16 --fp_reassoc=off --float_operations_allowed=all --ramfunc=off --emit_warnings_as_errors -O3 --opt_for_speed=4 -DNDEBUG --symdebug:none --c++14
Code
#include <xdc/runtime/System.h> #include <array> class Q { public: Q() : member{5} {} int member; }; struct A { int a; int b; int c; int d; }; struct B { A a; Q q; }; void modifyStack() { std::array<int, 16> values{}; for (int i = 0; i < values.size(); ++i) { values[i] = i; } } void initializeAndPrint() { // Aggregate initialization with {}. dcl.init.aggr/7 // The members a,b,c,d are not initialized. // The class member is initialized through default constructor. B b{}; System_printf("b.a.a: %d\n", b.a.a); System_printf("b.a.b: %d\n", b.a.b); System_printf("b.a.c: %d\n", b.a.c); System_printf("b.a.d: %d\n", b.a.d); System_printf("b.q.member: %d\n", b.q.member); } void init() { modifyStack(); initializeAndPrint(); }
Output
b.a.a: 12 b.a.b: 13 b.a.c: 14 b.a.d: 15 b.q.member: 5