What exactly is warning C4718 (Visual Studio)?

link msdn

text here:

'function call: a recursive call has no side effects, deleting

A function contains a recursive call, but otherwise has no side effects. A call to this function is deleted. The correctness of the program is not affected, but there is behavior. If you leave the in call, you may throw an exception at runtime, deleting the call removes this opportunity.

Code causing this warning:

template<class Key, class Value>
void Map<Key, Value>::Clear(NodeType* pNode)
{
    ((Key*) (pNode->m_key))->~Key();
    ((Value*) (pNode->m_item))->~Value();

    NodeType* pL = pNode->GetLeftChild();
    NodeType* pR = pNode->GetRightChild();
    if (pL != &m_dummy)
    {
        Clear(pL);
    }
    if (pR != &m_dummy)
    {
        Clear(pR);
    }
}

and 1 more point: this warning occurs only in the release version (/ Ox)

What is this warning? Thank!

+4
source share
3 answers

, , ~Key ~Value . , , .

+6

-, , , .

, , , . , , Clear() .

: @MSalters, , - , Key Value , , .

2: , : initializer?

template struct Map<typename Key, typename Value> {
    Key key;
    Value value;

    Map(Key k, Value v) : key(k), value(v) {}
}
+4

MSalters, , , . , GetLeftChild() GetRightChild() NULL, , m_dummy NULL, . - , NULL, .

MSalters , Microsoft MSDN , func2() - func(). . .

// compile with optimizations
int func(int x)
{
    if (x > 1)
        return func(x - 1); // recursive call
    else
        return x;
}

void func2(void)
{
    func(10);  // deleted; no side effects and return value used
}


void main() 
{
    func2();
}
-1
source

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


All Articles