diff --git a/cfg/std.cfg b/cfg/std.cfg index 281db819d..5212261ca 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1291,7 +1291,7 @@ - + erfc(arg1) false @@ -1302,7 +1302,7 @@ - + erfc(arg1) false @@ -1313,7 +1313,7 @@ - + erfc(arg1) false diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 815f7b355..3fd5be1fb 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -730,6 +730,17 @@ static std::unordered_map createBuiltinLibr v.valueType = ValueFlow::Value::ValueType::FLOAT; return v; }; + functions["erfc"] = [](const std::vector& args) { + if (args.size() != 1) + return ValueFlow::Value::unknown(); + ValueFlow::Value v = args[0]; + if (!v.isFloatValue() && !v.isIntValue()) + return ValueFlow::Value::unknown(); + double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue; + v.floatValue = std::erfc(value); + v.valueType = ValueFlow::Value::ValueType::FLOAT; + return v; + }; functions["sqrt"] = [](const std::vector& args) { if (args.size() != 1) return ValueFlow::Value::unknown(); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index c242ad508..af8ac8e40 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -64,6 +64,13 @@ int zerodiv_erf() return 42 / i; } +int zerodiv_erfc() +{ + int i = std::erfc(42); + // cppcheck-suppress zerodiv + return 42 / i; +} + int zerodiv_asin() { int i = std::asin(0);