[LLVMbugs] [Bug 13730] New: decltype in declaration does not match up with definition, causing ambiguous overload

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 30 05:49:10 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13730

             Bug #: 13730
           Summary: decltype in declaration does not match up with
                    definition, causing ambiguous overload
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: bruno-llvm at defraine.net
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Consider this:

#include <utility> // std::declval

using namespace std;

template<typename T>
struct vec {
};

template<typename S, typename T>
vec<decltype(declval<S>() * declval<T>())> operator*(const vec<S>& v1, const
vec<T>& v2);

template<typename S, typename T>
vec<decltype(declval<S>() * declval<T>())> operator*(const vec<S>&, const
vec<T>&) {
    return vec<decltype(declval<S>() * declval<T>())>();
}

int main() {
    vec<double> v1, v2;
    v1 * v2;
}

This gives:

amb.cpp:19:5: fatal error: use of overloaded operator '*' is ambiguous (with
operand types 'vec<double>' and 'vec<double>')
        v1 * v2;
        ~~ ^ ~~
amb.cpp:10:44: note: candidate function [with S = double, T = double]
vec<decltype(declval<S>() * declval<T>())> operator*(const vec<S>& v1, const
vec<T>& v2);
                                           ^
amb.cpp:13:44: note: candidate function [with S = double, T = double]
vec<decltype(declval<S>() * declval<T>())> operator*(const vec<S>&, const
vec<T>&) {
                                           ^
1 error generated.

I only intend there to be one function "operator*", that is first declared and
then defined.

Somehow, the presence of "decltype" and "declval" in the return type prevents
the definition from matching up with the declaration, causing an ambiguous
overload?

This is:

Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.1.0
Thread model: posix

With -stdlib=libc++

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list