diff options
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 26 | ||||
-rw-r--r-- | test/CXX/over/over.match/over.match.best/p1.cpp | 16 |
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 03ac2d9bb7..e64080ea6a 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3472,10 +3472,10 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, if (Cand1.IgnoreObjectArgument || Cand2.IgnoreObjectArgument) StartArg = 1; - // (C++ 13.3.3p1): a viable function F1 is defined to be a better - // function than another viable function F2 if for all arguments i, - // ICSi(F1) is not a worse conversion sequence than ICSi(F2), and - // then... + // C++ [over.match.best]p1: + // A viable function F1 is defined to be a better function than another + // viable function F2 if for all arguments i, ICSi(F1) is not a worse + // conversion sequence than ICSi(F2), and then... unsigned NumArgs = Cand1.Conversions.size(); assert(Cand2.Conversions.size() == NumArgs && "Overload candidate mismatch"); bool HasBetterConversion = false; @@ -3497,14 +3497,24 @@ Sema::isBetterOverloadCandidate(const OverloadCandidate& Cand1, } } + // -- for some argument j, ICSj(F1) is a better conversion sequence than + // ICSj(F2), or, if not that, if (HasBetterConversion) return true; - // FIXME: Several other bullets in (C++ 13.3.3p1) need to be - // implemented, but they require template support. + // - F1 is a non-template function and F2 is a function template + // specialization, or, if not that, + if (Cand1.Function && !Cand1.Function->getPrimaryTemplate() && + Cand2.Function && Cand2.Function->getPrimaryTemplate()) + return true; + + // -- F1 and F2 are function template specializations, and the function + // template for F1 is more specialized than the template for F2 + // according to the partial ordering rules described in 14.5.5.2, or, + // if not that, + + // FIXME: Implement partial ordering of function templates. - // C++ [over.match.best]p1b4: - // // -- the context is an initialization by user-defined conversion // (see 8.5, 13.3.1.5) and the standard conversion sequence // from the return type of F1 to the destination type (i.e., diff --git a/test/CXX/over/over.match/over.match.best/p1.cpp b/test/CXX/over/over.match/over.match.best/p1.cpp new file mode 100644 index 0000000000..df5198357d --- /dev/null +++ b/test/CXX/over/over.match/over.match.best/p1.cpp @@ -0,0 +1,16 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +template<typename T> int &f0(T*, int); +float &f0(void*, int); + +void test_f0(int* ip, void *vp) { + // One argument is better... + int &ir = f0(ip, 0); + + // Prefer non-templates to templates + float &fr = f0(vp, 0); +} + +// Partial ordering of function template specializations will be tested +// elsewhere +// FIXME: Initialization by user-defined conversion is tested elsewhere |