Bug 89325 - [8 Regression] False warnings about "optimization attribute" on operators when -fno-ipa-cp-clone
Summary: [8 Regression] False warnings about "optimization attribute" on operators whe...
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.3.0
: P2 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/ml/gcc-patches/20...
Keywords: diagnostic
Depends on:
Reported: 2019-02-13 06:40 UTC by Hans L
Modified: 2021-05-14 11:32 UTC (History)
5 users (show)

See Also:
Known to work:
Known to fail: 7.4.0, 8.2.0, 9.0
Last reconfirmed: 2019-02-13 00:00:00

minimum test case (141 bytes, text/plain)
2019-02-13 06:40 UTC, Hans L

Note You need to log in before you can comment on or make changes to this bug.
Description Hans L 2019-02-13 06:40:23 UTC
Created attachment 45687 [details]
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;  }  };
Comment 1 Martin Liška 2019-02-13 07:53:11 UTC
Confirmed, started with r236129 and is probably hidden on trunk due to r265744.
Comment 2 Jakub Jelinek 2019-04-12 09:40:17 UTC
Doesn't look like hidden to me, I'd say that r265744 has been the right fix for this.  The diagnose_mismatched_attributes has been simply placed way too early, before we check if the two decls actually shouldn't be merged because they have different arguments (and not extern "C").
I'd say we should just say this is fixed for 9 and decide how to fix on release branches.
Let me prepare a patch with some testcases for trunk.
Comment 3 Jakub Jelinek 2019-04-12 10:38:32 UTC
Testsuite patch https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00494.html
Comment 4 Jakub Jelinek 2019-04-17 19:25:29 UTC
Author: jakub
Date: Wed Apr 17 19:24:55 2019
New Revision: 270422

URL: https://gcc.gnu.org/viewcvs?rev=270422&root=gcc&view=rev
	PR c++/89325
	* g++.dg/ext/attrib58.C: New test.
	* g++.dg/ext/attrib59.C: New test.
	* g++.dg/ext/attrib60.C: New test.

Comment 5 Agner Fog 2019-04-30 08:16:42 UTC
I have the same problem.
Minimal test case:

#include <math.h>

struct Test {
    float f;

Test round(Test const & a) __attribute__ ((optimize("-fno-unsafe-math-optimizations")));
Test round(Test const & a) {return a;}
Comment 6 Christoph Hertzberg 2019-06-14 13:03:28 UTC
We just mask the warning for g++-7 at the moment.
Comment 7 Richard Biener 2019-11-14 07:53:36 UTC
The GCC 7 branch is being closed, re-targeting to GCC 8.4.
Comment 8 Jakub Jelinek 2020-03-04 09:34:49 UTC
GCC 8.4.0 has been released, adjusting target milestone.
Comment 9 Jakub Jelinek 2021-05-14 11:32:10 UTC
The GCC 8 branch is being closed, fixed in GCC 9.1.