Skip to content

Commit ee7c52e

Browse files
geoffw0Copilot
andcommitted
C++: Test throwing exception pointers
Exercise new-expression throws and exempt value throws and MFC-style CException subclasses for cpp/throwing-pointer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e82e887 commit ee7c52e

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:16:3:16:25 | throw ... | This should throw a MyException rather than a pointer to one. |
2+
| test.cpp:20:3:20:28 | throw ... | This should throw a OtherException rather than a pointer to one. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Best Practices/Exceptions/ThrowingPointers.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class MyException {
2+
};
3+
4+
class OtherException {
5+
};
6+
7+
// Microsoft MFC's CException hierarchy is intended to be thrown (and
8+
// caught) as a pointer, so it should not be flagged.
9+
class CException {
10+
};
11+
12+
class CMyFrameworkException : public CException {
13+
};
14+
15+
void throwsPointerToMyException() {
16+
throw new MyException(); // $ Alert
17+
}
18+
19+
void throwsPointerToOtherException() {
20+
throw new OtherException(); // $ Alert
21+
}
22+
23+
void throwsByValue() {
24+
throw MyException();
25+
}
26+
27+
void throwsFrameworkExceptionPointer() {
28+
throw new CMyFrameworkException();
29+
}

0 commit comments

Comments
 (0)