title: Ambiguous call to abs
body: <p>I have a custom data type that in practice can be either <code>float</code> or <code>double</code>. On every OS except OSX, I am able to successfully build this C++11 template:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cstdint&gt;
  
  template&lt; class REAL_T &gt;
  inline REAL_T inhouse_abs(REAL_T i_val)
  {
      return std::abs((REAL_T)i_val);
  }
  
  int main()
  {
      int32_t ui = 2;
      inhouse_abs(ui);
      return 0;
  }
  </code></pre>
  
  <p>However, clang 6.0 (3.5 LLVM) reports an ambiguous function call. If I change <code>abs</code> to <code>fabs</code>, the error is resolved on OSX, but now an identical error shows up on my Linux clang, gcc, and Visual Studio.</p>
  
  <p>Error on Visual Studio with fabs:</p>
  
  <pre><code>349 error C2668: 'fabs' : ambiguous call to overloaded function
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This example compiled on our OS X systems, although in the <em>nearly</em> identical project it does not. The solution was including <code>&lt;cstdlib&gt;</code> explicitly in the source, rather than back in another header. The reason is unclear, but seems to be xcode/clang not following our header includes properly.</p>