3

Here's the minimum example, start code analyze in visual studio 2019

#include <sal.h>
class CTest
{
public:
    virtual void A() = 0;
    virtual void B() const = 0;
    _Check_return_ _Ret_maybenull_ static CTest* GetInstance()
    {
        return (CTest*)0;
    }
};


void Test2()
{
    auto a = CTest::GetInstance();
    a->A();     // no warning ?

    auto b = CTest::GetInstance();
    b->B();     // warning C6011
} 

Why C6011 warning only taks effect on calling const member function of null class pointer. but not on non-const member function ? Apprantely both code will crash.

wwc
  • 101
  • 6

0 Answers0