Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

c++ - why vc++ Code Analyze for may-be-null mark raise C6011 on const member function only?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...