title: How can an the -I compiler option cause different warnings triggers?
body: <p>I was recently tasked with restructuring an application and ran into a rather bizarre issue. I've reduced the issue into example code as best as I can. Consider the following:</p>
  
  <p>offender.h</p>
  
  <pre><code>__attribute__ ((visibility ("default")))
  typedef struct A {
      int a;
  } A;
  </code></pre>
  
  <p>test.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;offender.h&gt;
  
  int main(void)
  {
      A a;
      a.a = 10;
      std::cout &lt;&lt; a.a &lt;&lt; "\n";
      return 0;
  }
  </code></pre>
  
  <p>If I run:</p>
  
  <pre><code>g++ -Wall -Werror -o test -I. test.cpp
  In file included from test.cpp:3:
  ./offender.h:4:3: error: ‘visibility’ attribute ignored [-Werror=attributes]
      4 | } A;
        |   ^
  cc1plus: all warnings being treated as errors
  make: *** [Makefile:3: all] Error 1
  </code></pre>
  
  <p>This makes sense, however, if I move offender.h into a system defined path and compile without the -I. I get this:</p>
  
  <pre><code>sudo mv offender.h /usr/local/include/
  g++ -Wall -Werror -o test test.cpp
  </code></pre>
  
  <p>No Warning is triggered.</p>
  
  <p>How is it possible that a warning occurs if I include the header file from the current directory but works fine if I include it from a pre-defined include directory? What am I missing?</p>
  
  <p>This has been tested with g++ 7.5.0 (Ubuntu 18.04) and 9.3.0 (Ubuntu 20.04), both generate the same output.</p>
  
  <p>Edit: Clarified the problem</p>