Bug 104534 - write-strings does not follow C++ standard
Summary: write-strings does not follow C++ standard
Status: RESOLVED DUPLICATE of bug 95596
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-14 20:02 UTC by johnsen.david@siemens.com
Modified: 2022-02-21 15:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description johnsen.david@siemens.com 2022-02-14 20:02:04 UTC
The bug is present in all versions of GCC from 6 to 11 and on GCC trunk.

example file ws.cpp:

#include <iostream>
void f(char*) { std::cout << "This compiler is broken"  << std::endl; }
void f(bool)  { std::cout << "This compiler is correct" << std::endl; }

int main() {
    f("This is supposed to work");
    return 0;
}

This program is a valid C++ and the standard is very clear on what the result should be.
As far as I know, there is no way to make GCC generate this result.

compiled with: c++ ws.cpp

Depending on the command line options, the program can:
* compile (and run incorrectly, -Wnowrite-strings),
* compile with a warning (still run incorrectly, -Wwrite-strings),
* or not compile at all (-Werror -Wwrite-strings).

The only outcome that I can't get is the correct one:
* The program compiles without errors and runs correctly.

Other compilers, such as clang++ and Visual Studio C++, follow the standard.
Comment 1 Andrew Pinski 2022-02-14 20:11:39 UTC
Dup of bug 95596.

*** This bug has been marked as a duplicate of bug 95596 ***
Comment 2 Eric Gallager 2022-02-21 15:31:06 UTC
see also bug 61579, too