https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114644
Bug ID: 114644 Summary: wrong -Wrestrict on snprintf() of distinct struct array members Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zsojka at seznam dot cz Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu Created attachment 57905 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57905&action=edit testcase Output: $ gcc-14 -Wall res.c -c res.c: In function ‘f2’: res.c:4:25: warning: ‘__builtin_snprintf’ argument 4 overlaps destination object ‘s’ [-Wrestrict] 4 | void f2(int i, int j) { __builtin_snprintf(s[i].a, 10, "%s", s[j].b); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ res.c:1:31: note: destination object referenced by ‘restrict’-qualified argument 1 was declared here 1 | struct { char a[10], b[10]; } s[10]; | ^ as far as I can tell, there should be no warning for snprintf(), as there is no warning for the other functions. I checked all the PRs in PR84774 and didn't find any this would be duplication. Of course I am not a language lawyer, so my understanding of 'restrict' might be incorrect; but the warning is at least inconsistent: - only snprintf() warns - the s[] must be an array - both i/j indices must be variables - -Wrestrict alone is not enough to trigger this -Wrestrict warning at -O0