Skip to content

Commit

Permalink
Fixed #12862 (std.cfg: std::is.. functions returns bool)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jun 20, 2024
1 parent 5c93df1 commit 269e5ce
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 13 deletions.
74 changes: 62 additions & 12 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3318,11 +3318,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
</arg>
</function>
<!-- int isfinite(double x); -->
<!-- bool isfinite(float x); // since C++11 -->
<!-- bool isfinite(double x); // since C++11 -->
<!-- bool isfinite(long double x); // since C++11 -->
<!-- bool isfinite(Integral x); // since C++11 -->
<function name="isfinite,std::isfinite">
<function name="isfinite">
<use-retval/>
<pure/>
<returnValue type="int"/>
Expand All @@ -3333,8 +3329,23 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-bool/>
</arg>
</function>
<!-- bool std::isfinite(float x); // since C++11 -->
<!-- bool std::isfinite(double x); // since C++11 -->
<!-- bool std::isfinite(long double x); // since C++11 -->
<!-- bool std::isfinite(Integral x); // since C++11 -->
<function name="std::isfinite">
<use-retval/>
<pure/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
<not-uninit/>
<not-bool/>
</arg>
</function>
<!-- int isgreater(double x, double y); -->
<function name="isgreater,std::isgreater">
<function name="isgreater">
<use-retval/>
<pure/>
<returnValue type="int">arg1&gt;arg2?1:0</returnValue>
Expand All @@ -3347,8 +3358,22 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-uninit/>
</arg>
</function>
<!-- bool std::isgreater(double x, double y); -->
<function name="std::isgreater">
<use-retval/>
<pure/>
<returnValue type="bool">arg1&gt;arg2?1:0</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
<not-uninit/>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
</function>
<!-- int isgreaterequal(double x, double y); -->
<function name="isgreaterequal,std::isgreaterequal">
<function name="isgreaterequal">
<use-retval/>
<pure/>
<returnValue type="int">arg1 &gt;= arg2?1:0</returnValue>
Expand All @@ -3361,12 +3386,22 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-uninit/>
</arg>
</function>
<!-- bool std::isgreaterequal(double x, double y); -->
<function name="std::isgreaterequal">
<use-retval/>
<pure/>
<returnValue type="bool">arg1 &gt;= arg2?1:0</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
<not-uninit/>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
</function>
<!-- int isinf(double x); -->
<!-- bool isinf(float x); // since C++11 -->
<!-- bool isinf(double x); // since C++11 -->
<!-- bool isinf(long double x); // since C++11 -->
<!-- bool isinf(Integral x); // since C++11 -->
<function name="isinf,std::isinf">
<function name="isinf">
<use-retval/>
<pure/>
<returnValue type="int"/>
Expand All @@ -3377,6 +3412,21 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-bool/>
</arg>
</function>
<!-- bool std::isinf(float x); // since C++11 -->
<!-- bool std::isinf(double x); // since C++11 -->
<!-- bool std::isinf(long double x); // since C++11 -->
<!-- bool std::isinf(Integral x); // since C++11 -->
<function name="std::isinf">
<use-retval/>
<pure/>
<returnValue type="bool"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
<not-uninit/>
<not-bool/>
</arg>
</function>
<!-- double logb(double x); -->
<function name="logb,std::logb">
<use-retval/>
Expand Down
28 changes: 27 additions & 1 deletion test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,13 @@ void uninitvar_fpclassify(void)
(void)std::fpclassify(ld);
}

void bool_isfinite(float f)
{
// cppcheck-suppress compareBoolExpressionWithInt
// cppcheck-suppress knownConditionTrueFalse
if (std::isfinite(f)==123) {}
}

void uninitvar_isfinite(void)
{
float f;
Expand All @@ -2700,6 +2707,12 @@ void uninitvar_isfinite(void)
(void)std::isfinite(ld);
}

void bool_isgreater(float f)
{
// cppcheck-suppress compareBoolExpressionWithInt
if (std::isgreater(f)==123) {}
}

void uninitvar_isgreater(void)
{
float f1,f2;
Expand All @@ -2715,6 +2728,12 @@ void uninitvar_isgreater(void)
(void)std::isgreater(ld1,ld2);
}

void bool_isgreaterequal(float f)
{
// cppcheck-suppress compareBoolExpressionWithInt
if (std::isgreaterequal(f)==123) {}
}

void uninitvar_isgreaterequal(void)
{
float f1,f2;
Expand All @@ -2730,6 +2749,13 @@ void uninitvar_isgreaterequal(void)
(void)std::isgreaterequal(ld1,ld2);
}

void bool_isinf(float f)
{
// cppcheck-suppress compareBoolExpressionWithInt
// cppcheck-suppress knownConditionTrueFalse
if (std::isinf(f)==123) {}
}

void uninitvar_isinf(void)
{
double d;
Expand Down Expand Up @@ -5085,4 +5111,4 @@ void constParameterReference_assign(std::vector<int>& v, int& r) {
void constParameterReference_insert(std::list<int>& l, int& r) {
l.insert(l.end(), r);
l.insert(l.end(), 5, r);
}
}

0 comments on commit 269e5ce

Please sign in to comment.