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

            Bug ID: 61579
           Summary: -Wwrite-strings does not behave as a warning option
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx

Unlike other -W family options, -Wwrite-strings does not actually behave as a
warning option but as an option that alters the language semantics. I think
this inconsistency should be considered a bug and fixed. It leads to multiple
issues:

1. Warning messages wrongly show as [enabled by default] rather than
[-Wwrite-strings], since discarding const qualifier is enabled by default.

2. Some code which should produce a warning actually produces an error. As a
trivial but stupid example, if(0)*""=0; One can of course construct
non-trivial, non-stupid examples of this, particularly with the ?: operator.

3. The semantics of code using __typeof__, ?:, and now more importantly with
C11, _Generic, are changed by -Wwrite-strings. As a particularly bad case, I
think this could lead to the introduction of aliasing violations and undefined
behavior in code that had well-defined behavior without -Wwrite-strings.

Ideally the current implementation of -Wwrite-strings should be scrapped and
replaced with one that actually detects particular usage that's deemed
dangerous rather than changing the language semantics.

Reply via email to