Alexey Biryukov - 4 days ago

I should have posted that to trac but I still don't have confirmation email received.

struct Parser
{
    Parser& parse(int&);
};

struct X
{
    int x, y;
    explicit X( Parser& p ) 
    {
        p.parse(x).parse(y);
//      p.parse(y);
    }
};

void main()
{
    X x ( Parser() );
    std::cout << x.x << x.y;
}

cpp-check 1.77 issues a warning for that:

(warning) Member variable 'X::y' is not initialized in the constructor.

No warning is issued for X::x at the same time.
If the commented line is uncommented, no warning is issued.

As far as I understand this, whenever a member variable is referenced in a call from ctor code, it's considered initialized by that code. (BTW this is true even if parse() takes its argument by value rather than by reference, which is ridiculous.) However the second element in the chained call to parse() appears to be ignored, which causes false positive for y.

 
Last edit: Alexey Biryukov 4 days ago