Skip to content

Commit

Permalink
std.cfg: Added support for std::unexpected(). (#6343)
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitcowboy authored Apr 26, 2024
1 parent b7360ce commit 80833e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cfg/cppcheck-cfg.rng
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
</attribute>
</optional>
<empty/>
</element>
</element>
</optional>
<optional>
<element name="pure"><empty/></element>
Expand Down Expand Up @@ -573,7 +573,7 @@
</element>
</choice>
</zeroOrMore>
</element>
</element>
</optional>
</element>

Expand Down Expand Up @@ -651,7 +651,7 @@
<param name="maxInclusive">2</param>
</data>
</define>

<define name="ARG-DIRECTION">
<choice>
<value>in</value>
Expand Down Expand Up @@ -720,7 +720,7 @@
<value>empty</value>
</choice>
</define>

<define name="MINSIZE-VALUE">
<data type="unsignedLong">
<param name="minInclusive">1</param>
Expand Down
7 changes: 7 additions & 0 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
<function name="abort,std::abort,std::terminate">
<noreturn>true</noreturn>
</function>
<!-- void unexpected(); (until C++11) -->
<!-- [[noreturn]] void unexpected(); (since C++11) -->
<!-- (deprecated)(removed in C++17) -->
<function name="std::unexpected">
<noreturn>true</noreturn>
<warn severity="style" alternatives="std::terminate" reason="Obsolete"/>
</function>
<!-- int abs(int j); -->
<function name="abs,std::abs">
<use-retval/>
Expand Down
10 changes: 10 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
#include <span>
#endif

#if __cplusplus <= 201402L
void unreachableCode_std_unexpected(int &x)
{
// cppcheck-suppress unexpectedCalled
std::unexpected();
// cppcheck-suppress unreachableCode
x=42;
}
#endif

void unreachableCode_std_terminate(int &x)
{
std::terminate();
Expand Down

0 comments on commit 80833e1

Please sign in to comment.