https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94741
Bug ID: 94741 Summary: stringop-truncation is triggered or not depending on surrounding members Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: danregister at poczta dot fm Target Milestone: --- The example code compiled with "-Wall -Werror -O2" gives: main.cpp: In constructor ‘S3::S3(const char*)’: main.cpp:26:22: error: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' specified bound 5 equals destination size [-Werror=stringop-truncation] 26 | __builtin_strncpy(a_, a, kMaxLen); It complains only about S3 while it should complain about all of them. The example code: constexpr auto kMaxLen = 5; struct S1 { // just array S1(const char* a); char a_[kMaxLen]; }; S1::S1(const char* a) { __builtin_strncpy(a_, a, kMaxLen); } struct S2 { // int member before array S2(const char* a); int n_; char a_[kMaxLen]; }; S2::S2(const char* a) { __builtin_strncpy(a_, a, kMaxLen); } struct S3 { // int member after array S3(const char* a); char a_[kMaxLen]; int n_; }; S3::S3(const char* a) { __builtin_strncpy(a_, a, kMaxLen); }