考虑如下代码段:

#include <iostream>

class Foo {
public:
    void Thunk()
    {
        auto lambda = [](Foo* f, const char* msg) {
            auto pfn = &Foo::Print;  // complained this statement
            (*f.*pfn)(msg);
        };

        lambda(this, "abc");
    }

    void Print(const char* msg)
    {
        std::cout << msg << std::endl;
    }
};

int main()
{
    Foo foo;

    foo.Thunk();

    return 0;
}

在 Visual Studio 2013 with update 5 上会提示编译警告:

Line 16: warning C4573: the usage of ‘Foo::Print’ requires the compiler to capture ‘this’ but the current default capture mode does not allow it

然而相同的代码在 Visual Studio 2017 上,以及 clang 3.8 上均不会出现类似警告。

我在 StackOverflow 上提了一个问题,然而截止本文发布前,并没有看起来靠谱的答案出现。