title: Why do C++ deprecated warnings print twice?
body: <p>If I have</p>
  
  <pre class="lang-cpp prettyprint-override"><code>namespace foo {
      inline int bar() {
          return 1119;
      }
  }
  
  __attribute__((deprecated)) inline int bar() {
      return 138;
  }
  </code></pre>
  
  <p>in <code>header.h</code> and</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "header.h"
  #include &lt;iostream&gt;
  
  int main() {
      int x = bar();
      int y = foo::bar();
      std::cout &lt;&lt; x &lt;&lt; std::endl;
      std::cout &lt;&lt; y &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>in <code>source.cpp</code>, then</p>
  
  <pre class="lang-sh prettyprint-override"><code>g++ source.cpp -o deprecated-test
  </code></pre>
  
  <p>results in </p>
  
  <pre><code>source.cpp: In function ‘int main()’:
  source.cpp:5:17: warning: ‘int bar()’ is deprecated [-Wdeprecated-declarations]
       int x = bar();
                   ^
  In file included from source.cpp:1:
  header.h:7:40: note: declared here
   __attribute__((deprecated)) int bar() {
                                   ^~~
  source.cpp:5:17: warning: ‘int bar()’ is deprecated [-Wdeprecated-declarations]
       int x = bar();
                   ^
  In file included from source.cpp:1:
  header.h:7:40: note: declared here
   __attribute__((deprecated)) int bar() {
  </code></pre>
  
  <p>(on Ubuntu 18.10 with g++ 8.2.0).</p>
  
  <p><strong>Why does the deprecated warning print twice?</strong></p>
  
  <p>Heading off some suggestions that would be unhelpful:</p>
  
  <ul>
  <li><p><code>[[deprecated]]</code>:
  I know with C++14 on you can use the <code>[[deprecated]]</code> attribute, but I need to work with C++11.</p></li>
  <li><p>Declaration vs. definition: <a href="https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes" rel="nofollow noreferrer">The docs</a> seem to imply it should be used with function declaration rather than definition, but </p>
  
  <ol>
  <li>I need to define the functions <code>inline</code> in a header rather than declare in the header and define in source files; and</li>
  <li>Trying this approach didn't stop the warning from printing twice anyway.</li>
  </ol></li>
  </ul>