<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Overload resolution is strange with constexpr"
   href="https://llvm.org/bugs/show_bug.cgi?id=26504">26504</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Overload resolution is strange with constexpr
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this:

Nicos-MBP:llvm-build thakis$ cat test.cc
template<class T> const T& min(const T& a, const T& b) {
  return a < b ? a : b;
}
struct A {
  A();
  operator int() const;
  operator unsigned() const;

  A foo() const {
    return min(*this, A());
  }
};
inline bool operator<(const A &a, const A &b) { return true; }
Nicos-MBP:llvm-build thakis$ bin/clang -c test.cc -std=c++11


This builds fine. Now make max() constexpr:


Nicos-MBP:llvm-build thakis$ bin/clang -c test.cc -std=c++11
test.cc:2:12: error: use of overloaded operator '<' is ambiguous (with operand
types 'const A' and 'const A')
  return a < b ? a : b;
         ~ ^ ~
test.cc:10:12: note: in instantiation of function template specialization
'min<A>' requested here
    return min(*this, A());
           ^
test.cc:2:12: note: because of ambiguity in conversion of 'const A' to 'float'
  return a < b ? a : b;
           ^
test.cc:6:3: note: candidate function
  operator int() const;
  ^
test.cc:7:3: note: candidate function
  operator unsigned() const;
  ^
test.cc:2:12: note: because of ambiguity in conversion of 'const A' to 'float'
  return a < b ? a : b;
           ^
test.cc:6:3: note: candidate function
  operator int() const;
  ^
test.cc:7:3: note: candidate function
  operator unsigned() const;
  ^
test.cc:2:12: note: built-in candidate operator<(float, float)
  return a < b ? a : b;
           ^
test.cc:2:12: note: built-in candidate operator<(float, double)
test.cc:2:12: note: built-in candidate operator<(float, long double)
test.cc:2:12: note: built-in candidate operator<(float, int)
test.cc:2:12: note: built-in candidate operator<(float, long)
test.cc:2:12: note: built-in candidate operator<(float, long long)
test.cc:2:12: note: built-in candidate operator<(float, __int128)
test.cc:2:12: note: built-in candidate operator<(float, unsigned int)
test.cc:2:12: note: built-in candidate operator<(float, unsigned long)
test.cc:2:12: note: built-in candidate operator<(float, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(float, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(double, float)
test.cc:2:12: note: built-in candidate operator<(double, double)
test.cc:2:12: note: built-in candidate operator<(double, long double)
test.cc:2:12: note: built-in candidate operator<(double, int)
test.cc:2:12: note: built-in candidate operator<(double, long)
test.cc:2:12: note: built-in candidate operator<(double, long long)
test.cc:2:12: note: built-in candidate operator<(double, __int128)
test.cc:2:12: note: built-in candidate operator<(double, unsigned int)
test.cc:2:12: note: built-in candidate operator<(double, unsigned long)
test.cc:2:12: note: built-in candidate operator<(double, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(double, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(long double, float)
test.cc:2:12: note: built-in candidate operator<(long double, double)
test.cc:2:12: note: built-in candidate operator<(long double, long double)
test.cc:2:12: note: built-in candidate operator<(long double, int)
test.cc:2:12: note: built-in candidate operator<(long double, long)
test.cc:2:12: note: built-in candidate operator<(long double, long long)
test.cc:2:12: note: built-in candidate operator<(long double, __int128)
test.cc:2:12: note: built-in candidate operator<(long double, unsigned int)
test.cc:2:12: note: built-in candidate operator<(long double, unsigned long)
test.cc:2:12: note: built-in candidate operator<(long double, unsigned long
long)
test.cc:2:12: note: built-in candidate operator<(long double, unsigned
__int128)
test.cc:2:12: note: built-in candidate operator<(int, float)
test.cc:2:12: note: built-in candidate operator<(int, double)
test.cc:2:12: note: built-in candidate operator<(int, long double)
test.cc:2:12: note: built-in candidate operator<(int, int)
test.cc:2:12: note: built-in candidate operator<(int, long)
test.cc:2:12: note: built-in candidate operator<(int, long long)
test.cc:2:12: note: built-in candidate operator<(int, __int128)
test.cc:2:12: note: built-in candidate operator<(int, unsigned int)
test.cc:2:12: note: built-in candidate operator<(int, unsigned long)
test.cc:2:12: note: built-in candidate operator<(int, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(int, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(long, float)
test.cc:2:12: note: built-in candidate operator<(long, double)
test.cc:2:12: note: built-in candidate operator<(long, long double)
test.cc:2:12: note: built-in candidate operator<(long, int)
test.cc:2:12: note: built-in candidate operator<(long, long)
test.cc:2:12: note: built-in candidate operator<(long, long long)
test.cc:2:12: note: built-in candidate operator<(long, __int128)
test.cc:2:12: note: built-in candidate operator<(long, unsigned int)
test.cc:2:12: note: built-in candidate operator<(long, unsigned long)
test.cc:2:12: note: built-in candidate operator<(long, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(long, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(long long, float)
test.cc:2:12: note: built-in candidate operator<(long long, double)
test.cc:2:12: note: built-in candidate operator<(long long, long double)
test.cc:2:12: note: built-in candidate operator<(long long, int)
test.cc:2:12: note: built-in candidate operator<(long long, long)
test.cc:2:12: note: built-in candidate operator<(long long, long long)
test.cc:2:12: note: built-in candidate operator<(long long, __int128)
test.cc:2:12: note: built-in candidate operator<(long long, unsigned int)
test.cc:2:12: note: built-in candidate operator<(long long, unsigned long)
test.cc:2:12: note: built-in candidate operator<(long long, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(long long, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(__int128, float)
test.cc:2:12: note: built-in candidate operator<(__int128, double)
test.cc:2:12: note: built-in candidate operator<(__int128, long double)
test.cc:2:12: note: built-in candidate operator<(__int128, int)
test.cc:2:12: note: built-in candidate operator<(__int128, long)
test.cc:2:12: note: built-in candidate operator<(__int128, long long)
test.cc:2:12: note: built-in candidate operator<(__int128, __int128)
test.cc:2:12: note: built-in candidate operator<(__int128, unsigned int)
test.cc:2:12: note: built-in candidate operator<(__int128, unsigned long)
test.cc:2:12: note: built-in candidate operator<(__int128, unsigned long long)
test.cc:2:12: note: built-in candidate operator<(__int128, unsigned __int128)
test.cc:2:12: note: built-in candidate operator<(unsigned int, float)
test.cc:2:12: note: built-in candidate operator<(unsigned int, double)
test.cc:2:12: note: built-in candidate operator<(unsigned int, long double)
test.cc:2:12: note: built-in candidate operator<(unsigned int, int)
test.cc:2:12: note: built-in candidate operator<(unsigned int, long)
test.cc:2:12: note: built-in candidate operator<(unsigned int, long long)
test.cc:2:12: note: built-in candidate operator<(unsigned int, __int128)
test.cc:2:12: note: built-in candidate operator<(unsigned int, unsigned int)
test.cc:2:12: note: built-in candidate operator<(unsigned int, unsigned long)
test.cc:2:12: note: built-in candidate operator<(unsigned int, unsigned long
long)
test.cc:2:12: note: built-in candidate operator<(unsigned int, unsigned
__int128)
test.cc:2:12: note: built-in candidate operator<(unsigned long, float)
test.cc:2:12: note: built-in candidate operator<(unsigned long, double)
test.cc:2:12: note: built-in candidate operator<(unsigned long, long double)
test.cc:2:12: note: built-in candidate operator<(unsigned long, int)
test.cc:2:12: note: built-in candidate operator<(unsigned long, long)
test.cc:2:12: note: built-in candidate operator<(unsigned long, long long)
test.cc:2:12: note: built-in candidate operator<(unsigned long, __int128)
test.cc:2:12: note: built-in candidate operator<(unsigned long, unsigned int)
test.cc:2:12: note: built-in candidate operator<(unsigned long, unsigned long)
test.cc:2:12: note: built-in candidate operator<(unsigned long, unsigned long
long)
test.cc:2:12: note: built-in candidate operator<(unsigned long, unsigned
__int128)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, float)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, double)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, long
double)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, int)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, long)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, long long)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, __int128)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, unsigned
int)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, unsigned
long)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, unsigned
long long)
test.cc:2:12: note: built-in candidate operator<(unsigned long long, unsigned
__int128)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, float)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, double)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, long
double)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, int)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, long)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, long long)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, __int128)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, unsigned
int)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, unsigned
long)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, unsigned
long long)
test.cc:2:12: note: built-in candidate operator<(unsigned __int128, unsigned
__int128)
1 error generated.



cl.exe builds this fine, and that's how it implements std::min().

a) Who is right?

b) If it's clang, we need to figure out what cl.exe does and accept that as an
extension.

(Also, the diagnostic is not very good.)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>