I believe that Cppcheck does not have such checker. Feel free to create a ticket in Trac. I would like that it contains a minimal example code with UB.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The following program can check a few things on this part of the standard. It is an extended version of the example in the standard.
struct A {
};
struct B : virtual A {
};
struct C : B {
C(int*);
};
struct D : virtual A {
D(A*);
int d;
};
struct X {
X(A);
X(int);
};
struct E : C, D, X {
E() : C(&d), // undefined behaviour: the construction of D has not started.
D(this), // undefined behaviour: upcast from E to A might use path E -> D -> A*
// but D is not constructed.
X(this) {} // defined behaviour: upon construction of X, C/B/D/A sublattice is fully constructed
};
struct F : C, D, X {
F() : C(&f), // defined behaviour: F() has started
D((C)this), // defined behaviour: F -> C is defined because F() has started,
// and C -> A* is defined because C is fully constructed
X(this) {} // defined behaviour: upon construction of X, C/B/D/A sublattice is fully constructed
int f;
};
int main(int argc, char* argv[])
{
return 0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't think cppcheck can identify the undefined behaviour described in N4713 15.7 section 2. My compiler also does not identify this.
BTW is section the correct term?
I believe that Cppcheck does not have such checker. Feel free to create a ticket in Trac. I would like that it contains a minimal example code with UB.
Do I need a different account to log in to Trac? I have made posts before on it.
yes.. well can you show a minimal example code here and I'll create a ticket.
The following program can check a few things on this part of the standard. It is an extended version of the example in the standard.
struct A {
};
struct B : virtual A {
};
struct C : B {
C(int*);
};
struct D : virtual A {
D(A*);
int d;
};
struct X {
X(A);
X(int);
};
struct E : C, D, X {
E() : C(&d), // undefined behaviour: the construction of D has not started.
D(this), // undefined behaviour: upcast from E to A might use path E -> D -> A*
// but D is not constructed.
X(this) {} // defined behaviour: upon construction of X, C/B/D/A sublattice is fully constructed
};
struct F : C, D, X {
F() : C(&f), // defined behaviour: F() has started
D((C)this), // defined behaviour: F -> C is defined because F() has started,
// and C -> A* is defined because C is fully constructed
X(this) {} // defined behaviour: upon construction of X, C/B/D/A sublattice is fully constructed
int f;
};
int main(int argc, char* argv[])
{
return 0;
}
Has a ticket been made for this?