Is it possible to enforce the use of operator new
strictly with std::nothrow
at compile time or at least during static analysis using pc-lint? Using c++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9) compiler.
enforce std::nothrow at compile time or during static analysis
180 views Asked by krizajb At
1
Yes, it's possible. GCC supports the
error
attribute, which makes any use of a particular function a hard error. Applying this tooperator new
has the expected effect.This is rejected by the compiler with:
Do note however that this applies only to code in which this custom declaration is visible. You may want to check the code of any libraries you use, including the standard library.