Issue 165766
Summary [clang-tidy] [windows] `bugprone-exception-escape` behaves weird
Labels clang-tidy
Assignees
Reporter ledror
    clang-tidy's `bugprone-exception-escape` check doesn't work as expected on windows builds.
Consider the following file:

```good.cpp
class Foo {};

Foo func() {
    throw 1;
}

class Bar {
public:
 ~Bar();
};

Bar::~Bar() {
    func()
}
```

When running clang-tidy with `bugprone-exception-escape`, we get, as expected, the following report:
```
> clang-tidy -checks="bugprone-exception-escape" good.cpp
...
good.cpp:12:6: warning: an exception may be thrown in function '~Bar' which should not throw exceptions [bugprone-exception-escape]
   12 | Bar::~Bar() {
```

Now consider the following file:

```bad.cpp
class Foo {};

Foo func() {
    throw 1;
}

class Bar {
public:
 ~Bar();
};

Bar::~Bar() {
    Foo foo = func();
 (void)foo;
}
```
When running the same command on windows we don't get any diagnostic.

On the other hand, with a macOS build we do get the expected message:
```
> clang-tidy -checks="bugprone-exception-escape" bad.cpp
...
bad.cpp:12:6: warning: an exception may be thrown in function '~Bar' which should not throw exceptions [bugprone-exception-escape]
   12 | Bar::~Bar() {
```

A weird case is that if the return type of `func` is an integral type (e.g int) and not a class, we do get the diagnostic on windows as well:
```weird.cpp
> clang-tidy -checks="bugprone-exception-escape" bad.cpp
...
bad.cpp:10:6: warning: an exception may be thrown in function '~Bar' which should not throw exceptions [bugprone-exception-escape]
   10 | Bar::~Bar() {
      |      ^
bad.cpp:2:5: note: frame #0: unhandled exception of type 'int' may be thrown in function 'func' here
    2 | throw 1;
      |     ^
bad.cpp:11:15: note: frame #1: function '~Bar' calls function 'func' here
   11 |     int foo = func();
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to