[clang-tidy] add option to `bugprone-exception-escape` to specify list of functions which do not throw
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```cpp
#include
struct FileCloser
{
FileCloser(FILE* f) : f(f) {}
~FileCloser() {
fclose(f);
}
FILE* f;
};
```
```
:6:5: warning: an exception may be thrown in function '~FileCloser' which should not throw exceptions [bugprone-exception-escape]
6 | ~FileCloser() {
| ^
/usr/include/stdio.h:178:12: note: frame #0: an exception of unknown type may be thrown in function 'fclose' here
178 | extern int fclose (FILE *__stream);
| ^
:7:9: note: frame #1: function '~FileCloser' calls function 'fclose' here
7 | fclose(f);
| ^
```
https://godbolt.org/z/3ohsfcrzM
`fclose()` is treated as throwing when `bugprone-exception-escape.TreatFunctionsWithoutSpecificationAsThrowing: OnlyUndefined` is set.
It would be helpful to be able to specify a list of functions which cannot throw.
I am not sure how helpful it would be to actually annotate C library functions as non-throwing. If somebody thinks that might be feasible I will file a separate ticket about it.
Contributor guide
Assessment
This issue has not been assessed yet.