title: ODR and internal linkage
body: <p>Assume that I have two compilation units in a single program, each of which declares a non-inline function with identical signatures, but differing in implementation, such as</p>
  
  <pre><code>// a.cpp
  namespace internal {
      int foo(int a) {
          return a+1;
      }
  }
  
  int main() {
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// b.cpp
  namespace internal {
      int foo(int b) {
          return b+2;
      }
  }
  </code></pre>
  
  <p>Compiling/linking this (g++ 4.8.3 with <code>-std=c++11</code>), I get an error</p>
  
  <pre><code>b.cpp:(.text+0x0): multiple definition of `internal::foo(int)'
  </code></pre>
  
  <p>which is rather expected, since, as far as I understand, this is simply a violation of the <a href="https://en.cppreference.com/w/cpp/language/definition" rel="nofollow noreferrer">one definition rule</a>:</p>
  
  <blockquote>
    <p>One and only one definition of every non-inline function or variable
    that is odr-used (see below) is required to appear in the entire
    program (including any standard and user-defined libraries).</p>
  </blockquote>
  
  <p>Now, changing the <code>namespace internal</code> into an unnamed namespace, the error goes away. Intuitively, this make sense to me, since I'm changing the function from <a href="https://en.cppreference.com/w/cpp/language/storage_duration" rel="nofollow noreferrer">external to internal linkage</a>:</p>
  
  <blockquote>
    <p>Any of the following names declared at namespace scope have external
    linkage unless the namespace is unnamed or is contained within an
    unnamed namespace (since C++11): variables and functions not listed
    above (that is, functions not declared static [...]) ...</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>[A]ll names declared in unnamed namespace or a namespace
    within an unnamed namespace, even ones explicitly declared extern,
    have internal linkage.</p>
  </blockquote>
  
  <p>However, I was unable to find anything in the one definition rule that exempts functions with internal linkage from it. Therefore, my question is: Is my intuitive reasoning correct, or am I still violating the one definition rule with functions that have internal linkage (and the compiler/linker just doesn't report it anymore)? Additionally, where does the standard (or cppreference.com <code>:)</code>) say whether or not it is ok?</p>