public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110005] New: Writable strings seem too greedy in overload resolution
@ 2023-05-27 16:05 arthur.j.odwyer at gmail dot com
2023-05-27 17:58 ` [Bug c++/110005] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2023-05-27 16:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110005
Bug ID: 110005
Summary: Writable strings seem too greedy in overload
resolution
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: arthur.j.odwyer at gmail dot com
Target Milestone: ---
I'm not clear on the entire behavior of -Wwrite-strings; bug 61579 seems
relevant. So there's probably an iceberg lurking below the surface. But here's
the tip, anyway.
// https://godbolt.org/z/Y5saPdozT
struct Evil {
Evil(const char*, const void*) { puts("1"); }
Evil(const char*, std::string) { puts("2"); }
Evil(const char*, char*) { puts("3"); }
};
int main() {
Evil e = {"", ""};
}
MSVC considers the only viable candidates #1 and #2.
Clang considers #1 and #2 preferable to #3, but will pick #3 if it's the only
candidate.
GCC considers #3 the *best* candidate, even better than #1.
Or again, something like this:
void f(const char *, std::string) { puts("4"); }
template<class T> void f(T *, std::remove_const_t<T> *) { puts("5");
int main() {
f("", "");
}
MSVC considers #4 the only viable candidate.
Clang considers #4 preferable to #5, but will pick #5 if it's the only
candidate.
GCC considers #5 the *best* candidate, even better than #4.
Obviously MSVC's behavior is the conforming one; but I understand GCC isn't
likely to go all the way *there*. Still, Clang's behavior strikes me as a
better compromise than GCC's.
As a consolation prize, assuming there's some way to turn off GCC's
writable-strings extension, could the text of -Wwrite-strings' warning message
be updated to provide that option? E.g. instead of the current
> warning: ISO C++ forbids converting a string constant to 'std::remove_const_t<const char>*' {aka 'char*'} [-Wwrite-strings]
it could say, like,
> warning: ISO C++ forbids converting a string constant to 'std::remove_const_t<const char>*' {aka 'char*'}; pass -fno-writable-strings to disable this extension [-Wwrite-strings]
or however the extension can actually be disabled.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/110005] Writable strings seem too greedy in overload resolution
2023-05-27 16:05 [Bug c++/110005] New: Writable strings seem too greedy in overload resolution arthur.j.odwyer at gmail dot com
@ 2023-05-27 17:58 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-27 17:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110005
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 95596.
*** This bug has been marked as a duplicate of bug 95596 ***
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-27 17:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-27 16:05 [Bug c++/110005] New: Writable strings seem too greedy in overload resolution arthur.j.odwyer at gmail dot com
2023-05-27 17:58 ` [Bug c++/110005] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).