CC: Alejandro

Am Samstag, dem 05.09.2026 um 15:52 -0400 schrieb Rich Felker:
> On Tue, Sep 01, 2026 at 04:19:34PM +0000, Joseph Myers wrote:
> > On Tue, 1 Sep 2026, Martin Uecker wrote:
> > 
> > > > I think -Wwrite-strings has been around for so long with its current 
> > > > semantics that it should be considered a semantic option that changes 
> > > > the 
> > > > type of string literals, despite its -W name; anything that does not 
> > > > change the type should be named differently.  (This does not prevent 
> > > > giving more precise diagnostics with -Wwrite-strings in the specific 
> > > > case 
> > > > of string literals, as long as they are consistent with still having 
> > > > const-qualified types - for example, as long as they remain pedwarns 
> > > > and 
> > > > typeof produces the const-qualified types.)
> > > 
> > > How about doing it the other way around: Instead of
> > > -fconst-string-literals turning on -Wwrite-strings we
> > > have -Wwrite-strings turn on -fconst-string-literals?  Then the
> > > behavior with just -Wwrite-strings remains the same as it always
> > > was, but one can independently toggle it using
> > > -fconst-string-literals (which then overwrites the default)? 
> > 
> > That seems reasonable (thus, with -Wwrite-strings 
> > -fno-const-string-literals as being the pure warning that does not change 
> > types and produces warnings rather than pedwarns).
> 
> Can we please just fix the bug? I can't see any code legitimately
> depending on -Wwrite-strings breaking language semantics. Someone who
> wants to use the warning should not need to know they need to couple
> it with -fno-const-string-literals to get the right behavior.
> 
> Rich

Note that I proposed that WG14 makes string literals const-qualified.
If they do the change, this would become a proper warning anyway in
future language modes.

Doing impact analyis for this change, I rebuild 10k Debian packages that
use  C.  Unfortunately,  -Wwrite-strings -Werror=discarded-qualifier
breaks a bit more than a third of those.  The good news is that
-Wwrite-string -Wno-error=discarded-qualifiers breaks only 9 packages
(3 using _Generic, 3 using a cast-to-union-member extension, and
3 where the logs are inclusive).  So changing the type of string
literals should be fine, but requires an implicit conversion for
backwards compatibility. 

This would also imply that changing the type back for -Wwrite-strings
should not be problematic.


Martin






Reply via email to