clang-concepts-monorepo
clang-concepts-monorepo copied to clipboard
overloaded functions with different constraint generates ambiguous call error
Following code generates ambiguous call error in the recent node of "concepts" branch (c01a40b29a0).
But it compiles ok in the version of the compiler explorer (godbolt.org) site !
I do not know this bug is fixed or newly created.
template< class ... Functors >
struct Overloaded : Functors ...
{
using Functors::operator () ...;
};
template< class ... FunctorArgs >
Overloaded( FunctorArgs ... ) -> Overloaded< FunctorArgs ... >;
template< class Type >
constexpr auto bar( Type t )
{
auto f =
Overloaded{
[]() requires ( sizeof( Type ) == sizeof( int ) ) { return 1; },
[]() requires ( sizeof( Type ) != sizeof( int ) ) { return 2; }
};
return f();
}
int main()
{
static_assert( 1 == bar( 0 ) );
static_assert( 2 == bar( 'a' ) );
return 0;
}
compiler log is :
C:/Desktop/test.cpp:19:9: error: call to object of type 'Overloaded<(lambda at C:/Desktop/test.cpp:15:4), (lambda at C:/Desktop/test.cpp:16:4)>' is ambiguous
return f();
^
C:/Desktop/test.cpp:35:22: note: in instantiation of function template specialization 'bar<int>' requested here
static_assert( 1 == bar( 0 ) );
^
C:/Desktop/test.cpp:15:4: note: candidate function
[]() requires ( sizeof( Type ) == sizeof( int ) ) { return 1; },
^
C:/Desktop/test.cpp:16:4: note: candidate function
[]() requires ( sizeof( Type ) != sizeof( int ) ) { return 2; }
^
C:/Desktop/test.cpp:15:4: note: conversion candidate of type 'int (*)()'
[]() requires ( sizeof( Type ) == sizeof( int ) ) { return 1; },
^
C:/Desktop/test.cpp:16:4: note: conversion candidate of type 'int (*)()'
[]() requires ( sizeof( Type ) != sizeof( int ) ) { return 2; }
^
C:/Desktop/test.cpp:19:9: error: call to object of type 'Overloaded<(lambda at C:/Desktop/test.cpp:15:4), (lambda at C:/Desktop/test.cpp:16:4)>' is ambiguous
return f();
^
C:/Desktop/test.cpp:36:22: note: in instantiation of function template specialization 'bar<char>' requested here
static_assert( 2 == bar( 'a' ) );
^
C:/Desktop/test.cpp:15:4: note: candidate function
[]() requires ( sizeof( Type ) == sizeof( int ) ) { return 1; },
^
C:/Desktop/test.cpp:16:4: note: candidate function
[]() requires ( sizeof( Type ) != sizeof( int ) ) { return 2; }
^
C:/Desktop/test.cpp:15:4: note: conversion candidate of type 'int (*)()'
[]() requires ( sizeof( Type ) == sizeof( int ) ) { return 1; },
^
C:/Desktop/test.cpp:16:4: note: conversion candidate of type 'int (*)()'
[]() requires ( sizeof( Type ) != sizeof( int ) ) { return 2; }
^
2 errors generated.