[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Jakub Jelinek changed: What|Removed |Added Status|ASSIGNED|RESOLVED CC||jakub at gcc dot gnu.org Resolution|--- |FIXED --- Comment #36 from Jakub Jelinek --- Should be fixed now.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #35 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:afb46540d3921e96c4cd7ba8fa2c8b0901759455 commit r15-7976-gafb46540d3921e96c4cd7ba8fa2c8b0901759455 Author: Jakub Jelinek Date: Tue Mar 11 23:08:38 2025 +0100 c: Don't emit -Wunterminated-string-initialization warning for multi-dimensional nonstring array initializers [PR117178] My/Kees' earlier patches adjusted -Wunterminated-string-initialization warning so that it doesn't warn about initializers of nonstring decls and that nonstring attribute is allowed on multi-dimensional arrays. Unfortunately as this testcase shows, we still warn about initializers of multi-dimensional array nonstring decls. The problem is that in that case field passed to output_init_element is actually INTEGER_CST, index into the array. For RECORD_OR_UNION_TYPE_P (constructor_type) field is a FIELD_DECL which we want to use, but otherwise (in arrays) IMHO we want to use constructor_fields (which is the innermost FIELD_DECL whose part is being initialized), or - if that is NULL - constructor_decl, the whole decl being initialized with multi-dimensional array type. 2025-03-11 Jakub Jelinek PR c/117178 * c-typeck.cc (output_init_element): Pass field to digest_init only for record/union types, otherwise pass constructor_fields if non-NULL and constructor_decl if constructor_fields is NULL. * gcc.dg/Wunterminated-string-initialization-2.c: New test.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #34 from Kees Cook --- Hi! The proposed patch fixes the warning for me. Thank you!
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #33 from Jakub Jelinek --- Created attachment 60692 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60692&action=edit gcc15-pr117178.patch Untested fix for the issue mentioned in https://gcc.gnu.org/pipermail/gcc-patches/2025-March/677134.html
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #32 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:1301e18f69ced6a14a7648a24d1eb3addd836b6c commit r15-7921-g1301e18f69ced6a14a7648a24d1eb3addd836b6c Author: Jakub Jelinek Date: Mon Mar 10 09:31:41 2025 +0100 gimple-ssa-warn-access: Adjust maybe_warn_nonstring_arg for nonstring multidimensional arrays [PR117178] The following patch fixes 4 xfails in attr-nonstring-11.c (and results in 2 false positive warnings in attr-nonstring-12.c not being produced either). The thing is that maybe_warn_nonstring_arg simply assumed that nonstring arrays must be single-dimensional, so when it sees a nonstring decl with ARRAY_TYPE, it just used its dimension. With multi-dimensional arrays that is not the right dimension to use though, it can be dimension of some outer dimension, e.g. if we have char a[5][6][7] __attribute__((nonstring)) if decl is a[5] it would assume maximum non-NUL terminated string length of 5 rather than 7, if a[5][6] it would assume 6 and only for a[5][6][0] it would assume the correct 7. So, the following patch looks through all the outer dimensions to reach the innermost one (which for attribute nonstring is guaranteed to have char/unsigned char/signed char element type). 2025-03-10 Jakub Jelinek PR c/117178 * gimple-ssa-warn-access.cc (maybe_warn_nonstring_arg): Look through multi-dimensional array types, stop at the innermost ARRAY_TYPE. * c-c++-common/attr-nonstring-11.c: Remove xfails. * c-c++-common/attr-nonstring-12.c (warn_strcmp_cst_1, warn_strcmp_cst_2): Don't expect any warnings here. (warn_strcmp_cst_3, warn_strcmp_cst_4): New functions with expected warnings.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #31 from Andrew Clayton --- Thanks everyone, looking forward to putting this to use!
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #30 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:ab714e60870d1bb98039652b760918b5e680ac10 commit r15-7901-gab714e60870d1bb98039652b760918b5e680ac10 Author: Jakub Jelinek Date: Sat Mar 8 00:50:13 2025 +0100 c-family, tree: Allow nonstring attribute on multidimensional arrays [PR117178] As requested in the PR117178 thread, the following patch allows nonstring attribute also on multi-dimensional arrays (with cv char/signed char/unsigned char as innermost element type) and pointers to such multi-dimensional arrays or pointers to single-dimensional cv char/signed char/unsigned char arrays. Given that (unfortunately) nonstring is a decl attribute rather than type attribute, I think restricting it to single-dimensional arrays makes no sense, even multi-dimensional ones can be used for storage of non-nul terminated strings. I really don't know what the kernel plans are, whether they'll go with -Wno-unterminated-string-initialization added in Makefiles, or whether the plan is to use nonstring attributes to quiet the warning. In the latter case, some of the nonstring attributes will need to be conditional on gcc version, because gcc before this patch will reject it on multidimensional arrays. 2025-03-08 Jakub Jelinek PR c/117178 gcc/ * tree.cc (get_attr_nonstring_decl): Look through all ARRAY_REFs, not just one and handle COMPONENT_REF and MEM_REF after skipping those rather than only when there wasn't ARRAY_REF. Formatting fix. gcc/c-family/ * c-attribs.cc (handle_nonstring_attribute): Allow the attribute also on multi-dimensional arrays with char/signed char/unsigned char element type or pointers to such single and multi-dimensional arrays. gcc/testsuite/ * c-c++-common/attr-nonstring-7.c: Remove one xfail. * c-c++-common/attr-nonstring-9.c: New test. * c-c++-common/attr-nonstring-10.c: New test. * c-c++-common/attr-nonstring-11.c: New test. * c-c++-common/attr-nonstring-12.c: New test. * c-c++-common/attr-nonstring-13.c: New test. * c-c++-common/attr-nonstring-14.c: New test. * c-c++-common/attr-nonstring-15.c: New test. * c-c++-common/attr-nonstring-16.c: New test.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #29 from Alejandro Colomar --- Hi Kees, (In reply to GCC Commits from comment #28) > The master branch has been updated by Jakub Jelinek : > > https://gcc.gnu.org/g:622968990beee7499e951590258363545b4a3b57 I guess I should have reviewed the commit message when I was in time. Anyway, here are a few comments for next time. :-) > > commit r15-7900-g622968990beee7499e951590258363545b4a3b57 > Author: Jakub Jelinek > Date: Fri Mar 7 23:59:34 2025 +0100 > > c: do not warn about truncating NUL char when initializing nonstring > arrays [PR117178] > > When initializing a nonstring char array when compiled with > -Wunterminated-string-initialization the warning trips even when > truncating the trailing NUL character from the string constant. Only > warn about this when running under -Wc++-compat since under C++ we should > not initialize nonstrings from C strings. The paragraph above is a bit unclear. If I'm understanding it correctly, I think the first sentence refers to the behavior before this patch? If so, using past might have been clearer. > gcc/c/ > * c-typeck.cc (digest_init): Add DECL argument. Adjust wording > of > pedwarn_init for too long strings and provide details on the > lengths, > for string literals where just the trailing NULL doesn't fit > warn for NULL is the null pointer constant. You meant NUL, which is the ASCII name for the null byte. Cheers, Alex
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #28 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:622968990beee7499e951590258363545b4a3b57 commit r15-7900-g622968990beee7499e951590258363545b4a3b57 Author: Jakub Jelinek Date: Fri Mar 7 23:59:34 2025 +0100 c: do not warn about truncating NUL char when initializing nonstring arrays [PR117178] When initializing a nonstring char array when compiled with -Wunterminated-string-initialization the warning trips even when truncating the trailing NUL character from the string constant. Only warn about this when running under -Wc++-compat since under C++ we should not initialize nonstrings from C strings. This patch separates the -Wunterminated-string-initialization and -Wc++-compat warnings, they are now independent option, the former implied by -Wextra, the latter not implied by anything. If -Wc++-compat is in effect, it takes precedence over -Wunterminated-string-initialization and warns regardless of nonstring attribute, otherwise if -Wunterminated-string-initialization is enabled, it warns only if there isn't nonstring attribute. In all cases, the warnings and also pedwarn_init for even larger sizes now provide details on the lengths. 2025-03-07 Kees Cook Jakub Jelinek PR c/117178 gcc/ * doc/invoke.texi (Wunterminated-string-initialization): Document the new interaction between this warning and -Wc++-compat and that initialization of decls with nonstring attribute aren't warned about. gcc/c-family/ * c.opt (Wunterminated-string-initialization): Don't depend on -Wc++-compat. gcc/c/ * c-typeck.cc (digest_init): Add DECL argument. Adjust wording of pedwarn_init for too long strings and provide details on the lengths, for string literals where just the trailing NULL doesn't fit warn for warn_cxx_compat with OPT_Wc___compat, wording which mentions "for C++" and provides details on lengths, otherwise for warn_unterminated_string_initialization adjust the warning, provide details on lengths and don't warn if get_attr_nonstring_decl (decl). (build_c_cast, store_init_value, output_init_element): Adjust digest_init callers. gcc/testsuite/ * gcc.dg/Wunterminated-string-initialization.c: Add additional test coverage. * gcc.dg/Wcxx-compat-14.c: Check in dg-warning for "for C++" part of the diagnostics. * gcc.dg/Wcxx-compat-23.c: New test. * gcc.dg/Wcxx-compat-24.c: New test. Signed-off-by: Kees Cook
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #27 from Andrew Clayton --- Thanks for the update!
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #26 from Sam James --- Jakub's revised patch: https://inbox.sourceware.org/gcc-patches/Z63vQc7tBvolrk27@tucnak/
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #25 from Sam James --- It's not my call, but given it's a new warning in 15, and this is a fairly significant UX issue with it, I think a case could be made. Kees should ping it when he gets a chance.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #24 from Andrew Clayton --- I take it it's too late for this to land in GCC 15? (I have immediate uses for this!).
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #23 from Alejandro Colomar --- If the attribute could be applied to a type, then you could apply it this way: alx@debian:~/tmp/gcc$ cat nonstring.c typeof(__attribute__((nonstring)) char [4]) tags[10]; alx@debian:~/tmp/gcc$ gcc -Wall -Wextra -S nonstring.c nonstring.c:1:1: warning: ‘nonstring’ attribute does not apply to types [-Wattributes] 1 | typeof(__attribute__((nonstring)) char [4]) tags[10]; | ^~
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #22 from Kees Cook --- On a related note, I need to be able to apply nonstring to arrays of char arrays. See bug #118095.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Eric Gallager changed: What|Removed |Added Keywords||patch Assignee|unassigned at gcc dot gnu.org |kees at outflux dot net URL||https://gcc.gnu.org/piperma ||il/gcc-patches/2024-Decembe ||r/671714.html Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2024-12-16 CC||egallager at gcc dot gnu.org
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #21 from Kees Cook --- Okay, now with tests and an updated truncation message. :) Please see: https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671714.html (Hopefully I have managed to get coding and commit log style correct...)
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #20 from Alejandro Colomar --- Hi Kees, (In reply to Kees Cook from comment #19) > Created attachment 59874 [details] > RFC for ignoring NUL byte with nonstring attribute > > Here's an RFC patch for allowing the NUL char truncation when the nonstring > attribute is present. I would s/exactly truncates/truncates/ in the diagnostic message. Cheers, Alex
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #19 from Kees Cook --- Created attachment 59874 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59874&action=edit RFC for ignoring NUL byte with nonstring attribute Here's an RFC patch for allowing the NUL char truncation when the nonstring attribute is present. I haven't added (or updated) test cases yet. Does this look like the right direction? (It also respects c++-compat.) Initial testing with the Linux kernel looks good.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
--- Comment #18 from Paul Eggert ---
(In reply to uecker from comment #17)
> Fairly limited, but if you only have specific cases where you need
> this, this worked for me as a workaround:
>
> #define TRUNC4(x) { x[0], x[1], x[2], x[3] }
> static char buf[4] = TRUNC4("");
Unfortunately that won't work for TZDB, first because the string length is
unknown, second because TZDB is portable and so cannot assume the GNU extension
of supporting ""[0] as a constant expression (the C standard does not
require this support).
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
uecker at gcc dot gnu.org changed:
What|Removed |Added
CC||uecker at gcc dot gnu.org
--- Comment #17 from uecker at gcc dot gnu.org ---
Fairly limited, but if you only have specific cases where you need
this, this worked for me as a workaround:
#define TRUNC4(x) { x[0], x[1], x[2], x[3] }
static char buf[4] = TRUNC4("");
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Paul Eggert changed: What|Removed |Added CC||eggert at cs dot ucla.edu --- Comment #16 from Paul Eggert --- I ran into a similar problem when using GCC pre-15 to compile the Time Zone Database code, which does this: #define TZDIR "/user/share/zoneinfo" ... static char const tzdirslash[sizeof TZDIR] = TZDIR "/"; where tzdirslash is a char array, not a string. I'd like to be able to tell GCC 15 "This is valid code and we know what we're doing here" without disabling the warning in general (a pragma push/pop should work but that's wayy to intrusive). Another possiblity, if the __attribute__((nonstring)) idea is too heavyweight, is to not issue the warning if the initialization ends in an empty string literal, e.g.: static char const tzdirslash[sizeof TZDIR] = TZDIR "/" ""; where the empty string literal tells GCC "don't warn". However, the __attribute__((nonstring)) approach would be cleaner if you have time to implement it.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #15 from Hans-Peter Nilsson --- (In reply to Andrew Pinski from comment #14) > > > Why are you all talking about C++? Yes, the docs mention C++ but this is a > > request for C. > > Because Wunterminated-string-initialization was added to warn about a > difference between c and c++ too. Again: yes, the docs mention C++, but this is a request for C.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #14 from Andrew Pinski --- (In reply to Hans-Peter Nilsson from comment #13) > The proposal makes sense to me too, particularly after reading the docs. > (Unless there's already a way to silence the warning for particular > constructs?) > Why are you all talking about C++? Yes, the docs mention C++ but this is a > request for C. Because Wunterminated-string-initialization was added to warn about a difference between c and c++ too.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Hans-Peter Nilsson changed: What|Removed |Added CC||hp at gcc dot gnu.org --- Comment #13 from Hans-Peter Nilsson --- The proposal makes sense to me too, particularly after reading the docs. (Unless there's already a way to silence the warning for particular constructs?) Why are you all talking about C++? Yes, the docs mention C++ but this is a request for C.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #12 from Alejandro Colomar --- (In reply to Andrew Pinski from comment #11) > (In reply to Alejandro Colomar from comment #9) > > > > I think it's simpler to have -Wc++-compat warn about any uses of > > [[gnu::nonstring]] at all, since C++ does not want such thing. That would > > cover all cases of unterminated initializations, so would keep Andrew happy, > > I think. Does it, Andrew? > > No because nonstring is still useful for C++ as it has nothing to do with > string literals. You just want to connect the two ideas because in C string > literals either can be with or without the nul terminating character (which > is unlike C++ where it is always with the nul terminating character). So, in C++ you are happy to have nonstring char*, but don't want to initialize them from string literals. I don't see why you would want to forbid that. Anyway, I think C shouldn't be bothered by C++'s design choices. Maybe -Wc++-compat could be the trigger for warning about those cases. Or maybe you could add -Wunterminated-string-initialization-c++ that is more noisy than the usual one. Or you could add an attribute for a string literal, but that would probably be complex. Are there any attributes that can be applied to lvalues?
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #11 from Andrew Pinski --- (In reply to Alejandro Colomar from comment #9) > > I think it's simpler to have -Wc++-compat warn about any uses of > [[gnu::nonstring]] at all, since C++ does not want such thing. That would > cover all cases of unterminated initializations, so would keep Andrew happy, > I think. Does it, Andrew? No because nonstring is still useful for C++ as it has nothing to do with string literals. You just want to connect the two ideas because in C string literals either can be with or without the nul terminating character (which is unlike C++ where it is always with the nul terminating character).
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
--- Comment #10 from Alejandro Colomar ---
(In reply to Alejandro Colomar from comment #9)
> (In reply to Kees Cook from comment #7)
> > Could "nonstring" be applied to string literals? (Like the "u" suffix idea,
> > but this would be more backward-compatible.) For example, from the example
> > in comment #1:
> >
> > { "BOOP", ... }
> >
> > becomes:
> >
> > { "BOOT" __attribute__((nonstring)), ... }
> >
> > and now it doesn't have a NUL-byte terminator?
> >
> > That would allow for trivial adjustment of the initializers, and leave the
> > -Wunterminated-string-initialization not having do make exceptions.
>
> I think it's simpler to have -Wc++-compat warn about any uses of
> [[gnu::nonstring]] at all, since C++ does not want such thing. That would
> cover all cases of unterminated initializations (that wouldn't be otherwise
> warned), so would keep Andrew happy,
> I think. Does it, Andrew?
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
--- Comment #9 from Alejandro Colomar ---
(In reply to Kees Cook from comment #7)
> Could "nonstring" be applied to string literals? (Like the "u" suffix idea,
> but this would be more backward-compatible.) For example, from the example
> in comment #1:
>
> { "BOOP", ... }
>
> becomes:
>
> { "BOOT" __attribute__((nonstring)), ... }
>
> and now it doesn't have a NUL-byte terminator?
>
> That would allow for trivial adjustment of the initializers, and leave the
> -Wunterminated-string-initialization not having do make exceptions.
I think it's simpler to have -Wc++-compat warn about any uses of
[[gnu::nonstring]] at all, since C++ does not want such thing. That would
cover all cases of unterminated initializations, so would keep Andrew happy, I
think. Does it, Andrew?
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #8 from Andrew Pinski --- Well for c++ udl is better ...
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
--- Comment #7 from Kees Cook ---
Could "nonstring" be applied to string literals? (Like the "u" suffix idea, but
this would be more backward-compatible.) For example, from the example in
comment #1:
{ "BOOP", ... }
becomes:
{ "BOOT" __attribute__((nonstring)), ... }
and now it doesn't have a NUL-byte terminator?
That would allow for trivial adjustment of the initializers, and leave the
-Wunterminated-string-initialization not having do make exceptions.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #6 from Alejandro Colomar --- (In reply to Jonathan Wakely from comment #5) > (In reply to Alejandro Colomar from comment #4) > > As for C++, maybe such an initialization should be acceptable as a GNU > > extension. > > Please, no. The C++ rule is a very deliberate language design choice. It > would not be a useful extension to directly contradict that unless users add > extra options to disable it again. Then I assume C++ doesn't have the [[gnu::nonstring]] attribute, and so this is not an issue in C++. Maybe you should diagnose when that attribute is used with -Wc++-compat, which would make it unnecessary to warn on the string initialization.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #5 from Jonathan Wakely --- (In reply to Alejandro Colomar from comment #4) > As for C++, maybe such an initialization should be acceptable as a GNU > extension. Please, no. The C++ rule is a very deliberate language design choice. It would not be a useful extension to directly contradict that unless users add extra options to disable it again.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #4 from Alejandro Colomar --- +1 The proposal makes sense to me. I had originally proposed something such as char x[3] = "foo"u; for marking that as a non-string. But that was because I didn't know about [[gnu::nonstring]]. The attribute makes more sense. As for C++, maybe such an initialization should be acceptable as a GNU extension. However, I don't care anymore what happens to C++, so whatever. :-) In C, this should certainly be silenceable with the attribute.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 --- Comment #3 from Andrew Pinski --- Note I almost want to say this should warn even with nostring due to the c++ compatibility reasons.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Andrew Pinski changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=116082 --- Comment #2 from Andrew Pinski --- Note this should still warn with the option for c++ compatibility still even if it is marked as nostring.
[Bug c/117178] -Wunterminated-string-initialization should ignore trailing NUL byte for nonstring char arrays
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178 Andrew Pinski changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=115185 --- Comment #1 from Andrew Pinski --- Note the warning is there partly for c++ compatibility.
