https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325
Bug ID: 89325 Summary: False warnings about "optimization attribute" on operators when -fno-ipa-cp-clone Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: thehans at gmail dot com Target Milestone: --- Created attachment 45687 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45687&action=edit minimum test case This is an issue I was having where g++ was outputting over 56,000 spurious warnings for a project I was building. I found that the problem only came from including Eigen/Core header amongst various project headers that declared operators. I was able to use singledelta to minimize the test case down to the attached file. After the #pragma which comes from Eigen, it seems to break g++'s ability to differentiate between different operator signatures and just warns that they are all previously defined with different attributes. Here is the warning output from g++: testcase-min.i:4:37: warning: optimization attribute on 'int& operator<<(int&, const B&)' follows definition but the attribute doesn't match [-Wattributes] int &operator<<(int &i, const B &ast); ^ testcase-min.i:1:35: note: previous definition of 'int& operator<<(int&, const A&)' was here class A { private: friend int &operator<<(int &i, const A &value) { return i; } }; ^~~~~~~~