https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178

--- Comment #12 from Alejandro Colomar <alx at kernel dot org> ---
(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?

Reply via email to