I ran into a problem while trying to call a member function inside a lambda for a captured one this. There is a constant and non-constant version of the function and it is intended for the type.
The following code shows an error:
struct TEST
{
template <typename T>
void test() {}
template <typename T>
void test() const {}
TEST()
{
[this]()
{
test<void>();
}();
}
};
Messages: http://rextester.com/MLU2098
source_file.cpp(13): error C2668: 'TEST::test': ambiguous call to overloaded function
source_file.cpp(7): note: could be 'void TEST::test<void>(void) const'
source_file.cpp(4): note: or 'void TEST::test<void>(void)'
source_file.cpp(13): note: while trying to match the argument list '()'
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
I was not sure if this behavior was correct and just a problem with the Microsoft compiler, so I tested the code with gcc and clang in the compiler explorer, and they both compiled the code without errors.
Which compiler displays the correct behavior here?
source
share