[llvm-bugs] [Bug 27967] New: -Wwrite-strings changes the actual type of string literals, meaning _Generic() behaves differently

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 1 10:32:52 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27967

            Bug ID: 27967
           Summary: -Wwrite-strings changes the actual type of string
                    literals, meaning _Generic() behaves differently
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ed at 80386.nl
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Hi there,

Consider the following piece of code:

_Static_assert(_Generic("Hi", char *: 1), "");

This code builds by default, as string literals seem to be of type "char *".
Now build the code with -Wwrite-strings:

bla.c:1:25: error: controlling expression type 'const char *' not compatible
with any generic association type

This compiler warning flag changes the actual underlying type of string
literals. Though I can imagine why it's implemented this way, this behaviour is
problematic. It means that a compiler warning flag may actually influence the
behaviour of code. Consider the following:

bool has_been_built_with_write_strings = _Generic("", char *: false, const char
*: true);

The compiler flag trickles down into the way code is generated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160601/3c975d3e/attachment.html>


More information about the llvm-bugs mailing list