http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51973
Bug #: 51973
Summary: [regression][C++0x] Template parameter deduction fails
for overloaded functions when template parameters have
defaulted arguments
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Source Code (bug.cc):
#include <type_traits>
#include <utility>
struct Less
{
template< class T, class U >
auto operator()( T const& x, U const& y ) const
-> decltype( x < y )
{
return x < y;
}
};
template< class T, class Comp = Less,
class = typename std::enable_if<
std::is_constructible< bool,
decltype(
std::declval<Comp&>()(
*std::declval<T const&>(),
*std::declval<T const&>()
)
)
>::value
>::type
>
inline bool pointee_before( T const& x, T const& y, Comp && comp = Comp() ) {
return y ? ( x ? bool( comp( *x, *y ) ) : true ) : false;
}
template< class T, class U, class Comp = Less,
class = typename std::enable_if<
std::is_constructible< bool,
decltype(
std::declval<Comp&>()(
*std::declval<T const&>(),
*std::declval<U const&>()
)
)
>::value
>::type
>
inline bool pointee_before( T const& x, U const& y, Comp && comp = Comp() ) {
return y ? ( x ? bool( comp( *x, *y ) ) : true ) : false;
}
int main()
{
int* p = 0;
int const* q = 0;
pointee_before( p, q );
}
Error Message:
bug.cc: In function 'int main()':
bug.cc:51:24: error: no matching function for call to 'pointee_before(int*&,
const int*&)'
bug.cc:51:24: note: candidates are:
bug.cc:26:13: note: template<class T, class Comp, class> bool
pointee_before(const T&, const T&, Comp&&)
bug.cc:26:13: note: template argument deduction/substitution failed:
bug.cc:51:24: note: deduced conflicting types for parameter 'const T' ('int*'
and 'const int*')
bug.cc:42:13: note: template<class T, class U, class Comp, class> bool
pointee_before(const T&, const U&, Comp&&)
bug.cc:42:13: note: template argument deduction/substitution failed:
bug.cc:31:3: error: 'std::declval<const int*&>()' cannot be used as a function
GCC Version:
gcc-4.7-20120121 (experimental)