Static Testing C++ Code
by Carlo Milanesi

Listing One

#include <complex>
#include <vector>
#include <algorithm>
#include <iostream>
int main() {
@LEGAL
    std::vector<std::complex<double> > v;
    std::min(2, 3);
@END
@ILLEGAL
    std::vector<std::complex<double> > v;
    sort(v.begin(), v.end());
@END
@ILLEGAL
    std::min(2, 3.);
@END
@LEGAL
    int i;
    std::cout << i;
    std::vector<int> vi;
    vi.push_back(3);
    vi.push_back(-2);
    vi.push_back(0);
    sort(vi.begin(), vi.end());
@END
}


Figure 1

==== Visual C++ test ====
Processing test file 'example.cpp'
Running "cl /nologo /GX /Za /Ox /W4 /WX _test1.cpp 2>NUL >NUL"
OK: Compilation with no errors nor warnings, as expected.
Running "cl /nologo /GX /Za /Ox _test2.cpp 2>NUL >NUL"
OK: Compilation with errors, as expected.
Running "cl /nologo /GX /Za /Ox _test3.cpp 2>NUL >NUL"
OK: Compilation with errors, as expected.
Running "cl /nologo /GX /Za /Ox /W4 /WX _test4.cpp 2>NUL >NUL"
Running "cl /nologo /GX /Za /Ox _test4.cpp 2>NUL >NUL"
*** WARNING: Compilation with no errors but some warnings, while a compilation w
ith no errors nor warnings was expected.
Failures: 0, warnings: 1, successes: 3

One test file processed.
 ..........
Total failures: 0, total warnings: 1, total successes: 3.



1


