C/C++ Specific Analysis

Source code analysis examines C/C++ source code and checks for C++ specific errors. It also points out places of improper code style and flaws in object-oriented design solutions.

The source checker detects issues with the following:

Example 1: Call of virtual function from constructor

1 #include "stdio.h"

2

3 class A {

4 public:

5 A() { destroy(); }

6 void destroy() { clear0();}

7 virtual void clear()=0;

8 void clear0() { clear(); };

9 };

10

11 class B : public A {

12 public:

13 B(){ }

14 virtual void clear(){ printf("overloaded clear"); }

15 virtual ~B() { }

16 };

17

18 int main() {

19 B b;

20 return 0;

21 }

The source checker issues the following message:

f1.cpp(8): warning #12327: pure virtual function "clear" is called from constructor (file:f1.cpp line:5)