[Bug c++/95596] New: string literal wrong overload resolution (char* vs std::string)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95596 Bug ID: 95596 Summary: string literal wrong overload resolution (char* vs std::string) Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bzsurr at protonmail dot com Target Milestone: --- Looking at the following code gcc calls the _char*_ overload, according to the standard the string literal is of type const array of char, so the non const char pointer should not be part of the overload set. #include #include void foo(char*) { puts("char*"); } void foo(std::string) { puts("std::string"); } int main() { foo("Hello World"); } Compiler Explorer Link: https://godbolt.org/z/82D4LT
[Bug c++/95596] string literal wrong overload resolution (char* vs std::string)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95596 --- Comment #1 from bzsurr at protonmail dot com --- (In reply to bzsurr from comment #0) > Looking at the following code gcc calls the _char*_ overload, according to > the standard the string literal is of type const array of char, so the non > const char pointer should not be part of the overload set. > > #include > #include > void foo(char*) { puts("char*"); } > void foo(std::string) { puts("std::string"); } > int main() > { > foo("Hello World"); > } > > > Compiler Explorer Link: > https://godbolt.org/z/82D4LT Compiler output: : In function 'int main()': :9:9: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 9 | foo("Hello World"); | ^