Explicit bool statement not called inside lambda - MSVC error?

#include <functional> struct T { explicit operator bool() { return true; } }; int main() { T t; if(t) {} // OK auto l = [&]() { if (t) {} // Error }; } 

MSVC's behavior looks strangely inconsistent; the only difference between the OK line and the error line is that it is in lambda. This is mistake?

+4
source share
1 answer

This is mistake?

Yes, definitely. There is nothing wrong with your program; in both cases, the bool conversion operator should be called.

+6
source

Source: https://habr.com/ru/post/1479968/


All Articles