https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84076
Bug ID: 84076 Summary: [5/6/7/8 Regression] Warning about objects through POD mistakenly claims the object is a pointer Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sgunderson at bigfoot dot com Target Milestone: --- Test program: #include <stdio.h> #include <string> int main(void) { std::string str; printf("%s\n", str); } GCC 4.9 and older gives: test.cpp: In function ‘int main()’: test.cpp:7:20: error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string<char>}’ through ‘...’ printf("%s\n", str); ^ GCC 5.0 and newer (including 7.3.0) prints: test.cpp: In function ‘int main()’: test.cpp:7:20: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}’ [-Wformat=] printf("%s\n", str); ^ This is a confusing warning, since it claims I'm sending a std::string * when I'm sending a std::string. In particular, in the program I was trying to fix this by adding ->c_str(), but .c_str() was the correct choice.