Skip to content

Commit 0b29e5c

Browse files
authored
Adding example to C26447
Updated the page with the example from the C++ Core Guidelines.
1 parent fc81365 commit 0b29e5c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/code-quality/c26447.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ This rule amends another rule, [C26440 DECLARE_NOEXCEPT](c26440.md), which tries
1818
- The rule focuses only on function calls. It flags targets that are not **`constexpr`** and that can potentially throw exceptions; in other words they are not marked explicitly as non-throwing by using **`noexcept`**, **`__declspec(nothrow)`**, **throw()**.
1919
- The compiler-generated target functions are skipped to reduce noise since exception specifications are not always provided by the compiler.
2020
- The checker also skips special kinds of target functions that are expected to be implemented as **`noexcept`**; this rule is enforced by [C26439 SPECIAL_NOEXCEPT](c26439.md).
21+
22+
# Example
23+
```cpp
24+
#include <vector>
25+
#include <string>
26+
#include <istream>
27+
28+
std::vector<std::string> collect(std::istream& is) noexcept
29+
{
30+
std::vector<std::string> res;
31+
for (std::string s; is >> s;) // C26447, `operator bool()` can throw, std::string's allocator can throw
32+
res.push_back(s); // C26447, `push_back` can throw
33+
return res;
34+
}
35+
```
36+
You can fix these warnings by removing noexcept from the function signature.

0 commit comments

Comments
 (0)