MATLAB: How to verify the custom definition of ‘new’ in PolySpace Server for C/C++

newpolyspacePolyspace Code ProverPolyspace Code Prover Server

When the operators like 'new' and 'delete' are redefined, you may experience a compilation problem due to a conflict between the PolySpace definition and your definition.
The error message will look like:
C:\PolySpace\PolySpaceForCandCPP_R2009a\Verifier\cppinclude\pst_stl\new.stdh, line xxx: error: exception specification is incompatible with that of previous function "operator new" (declared at line yyy of include_file.hpp")
void *operator new(size_t) throw(std::bad_alloc);

Best Answer

There are two ways to resolve the compilation problem:
1) Include a file include_file.hpp in the very beginning of the -include list :
-include "/path/to/include_file.hpp"
By doing this, the first declaration of 'new' (the one defined by you) will be considered.
2) Use the option -no-std-stubs (under 'Compliance with standards' in the PolySpace Launcher GUI). This does not include the PolySpace definition the definition you specify will be automatically considered.