consider template<typename T, typename... Args> T max( T a, T b, Args... args
);

template<typename T> T max( T a)
{
    return a;
}

template<typename T, typename... Args> T max( T a, T b, Args... args )
{
    return a > max<T>(b, args...) ? a : max<T>(b, args...);
}

#include <iostream>
int main()
{
        std::cout << max(3u, 2u, -1) << std::endl;
}

Guess, what it prints: 4294967295

That means, the -1 is converted from signed int to unsigned int in the call to
max(2u, -1) [ with T = unsigned int, Args = ], which may not occur in a
template lookup! The call should be rejected as invalid by the compiler,
because it must not find a definition for max(unsigned int, int).

This happens only in the recursion of the variadic template, calling max(3u,
-1) is rejected as desired.

gcc version 4.3.0-20080111


-- 
           Summary: Invalid conversion in lookup of variadic template
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rbuergel at web dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34877

Reply via email to