Skip to content

Commit c3665c5

Browse files
authored
Fix #15277 FP missingReturn: std::unreachable() is not configured as noreturn (#9081)
1 parent 7578129 commit c3665c5

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎cfg/std.cfg‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<noreturn>true</noreturn>
7676
<warn severity="style" alternatives="std::terminate" reason="Obsolete"/>
7777
</function>
78+
<!-- [[noreturn]] void std::unreachable(); (since C++23) -->
79+
<function name="std::unreachable">
80+
<noreturn>true</noreturn>
81+
</function>
7882
<!-- int abs(int j); -->
7983
<function name="abs,std::abs">
8084
<use-retval/>

‎test/cfg/std.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ void unreachableCode_std_terminate(int &x)
106106
x=42;
107107
}
108108

109+
#ifdef __cpp_lib_unreachable
110+
void unreachableCode_std_unreachable(int &x)
111+
{
112+
std::unreachable();
113+
// cppcheck-suppress unreachableCode
114+
x=42;
115+
}
116+
117+
int missingReturn_std_unreachable(int x) // #15277
118+
{
119+
if (x == 0)
120+
return 1;
121+
std::unreachable();
122+
}
123+
#endif
124+
109125
bool ignoredReturnValue_std_filesystem_exists(const std::filesystem::path &path, std::error_code& ec)
110126
{
111127
// cppcheck-suppress ignoredReturnValue

0 commit comments

Comments
 (0)