Skip to content

Commit e55bd4f

Browse files
committed
C++: Allow querying virtual, override, and final declaration specifiers.
1 parent d7c2979 commit e55bd4f

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Virtual function specifiers are now accessible via the new predicates on `Function` (`.isDeclaredVirtual`, `.isOverride`, and `.isFinal`).

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,23 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
8282
/** Holds if this function is inline. */
8383
predicate isInline() { this.hasSpecifier("inline") }
8484

85-
/** Holds if this function is virtual. */
85+
/**
86+
* Holds if this function is virtual.
87+
*
88+
* Unlike `isDeclaredVirtual()`, `isVirtual()` holds even if the function
89+
* is not explicitly declared with the `virtual` specifier.
90+
*/
8691
predicate isVirtual() { this.hasSpecifier("virtual") }
8792

93+
/** Holds if this function is declared with the `virtual` specifier. */
94+
predicate isDeclaredVirtual() { this.hasSpecifier("declared_virtual") }
95+
96+
/** Holds if this function is declared with the `override` specifier. */
97+
predicate isOverride() { this.hasSpecifier("override") }
98+
99+
/** Holds if this function is declared with the `final` specifier. */
100+
predicate isFinal() { this.hasSpecifier("final") }
101+
88102
/**
89103
* Holds if this function is deleted.
90104
* This may be because it was explicitly deleted with an `= delete`

cpp/ql/test/library-tests/clang_ms/element.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
| file://:0:0:0:0 | declaration of 1st parameter |
8080
| file://:0:0:0:0 | declared_constexpr |
8181
| file://:0:0:0:0 | declared_constinit |
82+
| file://:0:0:0:0 | declared_virtual |
8283
| file://:0:0:0:0 | decltype(nullptr) |
8384
| file://:0:0:0:0 | definition of fp_offset |
8485
| file://:0:0:0:0 | definition of gp_offset |
@@ -91,6 +92,7 @@
9192
| file://:0:0:0:0 | explicit |
9293
| file://:0:0:0:0 | extern |
9394
| file://:0:0:0:0 | far |
95+
| file://:0:0:0:0 | final |
9496
| file://:0:0:0:0 | float |
9597
| file://:0:0:0:0 | forceinline |
9698
| file://:0:0:0:0 | fp_offset |

cpp/ql/test/library-tests/conditions/elements.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
| file://:0:0:0:0 | const __va_list_tag & |
5050
| file://:0:0:0:0 | declared_constexpr |
5151
| file://:0:0:0:0 | declared_constinit |
52+
| file://:0:0:0:0 | declared_virtual |
5253
| file://:0:0:0:0 | decltype(nullptr) |
5354
| file://:0:0:0:0 | definition of <error> |
5455
| file://:0:0:0:0 | definition of fp_offset |
@@ -62,6 +63,7 @@
6263
| file://:0:0:0:0 | explicit |
6364
| file://:0:0:0:0 | extern |
6465
| file://:0:0:0:0 | far |
66+
| file://:0:0:0:0 | final |
6567
| file://:0:0:0:0 | float |
6668
| file://:0:0:0:0 | forceinline |
6769
| file://:0:0:0:0 | fp_offset |

cpp/ql/test/library-tests/specifiers2/specifiers2.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
| Function | specifiers2pp.cpp:10:18:10:24 | MyClass | MyClass | public |
4444
| Function | specifiers2pp.cpp:12:14:12:22 | publicFun | publicFun | inline |
4545
| Function | specifiers2pp.cpp:12:14:12:22 | publicFun | publicFun | public |
46+
| Function | specifiers2pp.cpp:13:21:13:26 | getInt | getInt | declared_virtual |
4647
| Function | specifiers2pp.cpp:13:21:13:26 | getInt | getInt | extern |
4748
| Function | specifiers2pp.cpp:13:21:13:26 | getInt | getInt | public |
4849
| Function | specifiers2pp.cpp:13:21:13:26 | getInt | getInt | pure |
4950
| Function | specifiers2pp.cpp:13:21:13:26 | getInt | getInt | virtual |
51+
| Function | specifiers2pp.cpp:14:21:14:21 | f | f | declared_virtual |
5052
| Function | specifiers2pp.cpp:14:21:14:21 | f | f | extern |
5153
| Function | specifiers2pp.cpp:14:21:14:21 | f | f | public |
5254
| Function | specifiers2pp.cpp:14:21:14:21 | f | f | virtual |
@@ -71,6 +73,7 @@
7173
| Function | specifiers2pp.cpp:24:7:24:7 | operator= | operator= | inline |
7274
| Function | specifiers2pp.cpp:24:7:24:7 | operator= | operator= | public |
7375
| Function | specifiers2pp.cpp:24:7:24:7 | operator= | operator= | public |
76+
| Function | specifiers2pp.cpp:26:21:26:21 | f | f | declared_virtual |
7477
| Function | specifiers2pp.cpp:26:21:26:21 | f | f | extern |
7578
| Function | specifiers2pp.cpp:26:21:26:21 | f | f | override |
7679
| Function | specifiers2pp.cpp:26:21:26:21 | f | f | public |

cpp/ql/test/library-tests/templates/instantiations_functions/elements.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
| file://:0:0:0:0 | declaration of 1st parameter |
110110
| file://:0:0:0:0 | declared_constexpr |
111111
| file://:0:0:0:0 | declared_constinit |
112+
| file://:0:0:0:0 | declared_virtual |
112113
| file://:0:0:0:0 | decltype(nullptr) |
113114
| file://:0:0:0:0 | definition of fp_offset |
114115
| file://:0:0:0:0 | definition of gp_offset |
@@ -121,6 +122,7 @@
121122
| file://:0:0:0:0 | explicit |
122123
| file://:0:0:0:0 | extern |
123124
| file://:0:0:0:0 | far |
125+
| file://:0:0:0:0 | final |
124126
| file://:0:0:0:0 | float |
125127
| file://:0:0:0:0 | forceinline |
126128
| file://:0:0:0:0 | fp_offset |

cpp/ql/test/library-tests/unnamed/elements.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| file://:0:0:0:0 | const | Other |
4242
| file://:0:0:0:0 | declared_constexpr | Other |
4343
| file://:0:0:0:0 | declared_constinit | Other |
44+
| file://:0:0:0:0 | declared_virtual | Other |
4445
| file://:0:0:0:0 | decltype(nullptr) | Other |
4546
| file://:0:0:0:0 | definition of fp_offset | Other |
4647
| file://:0:0:0:0 | definition of gp_offset | Other |
@@ -53,6 +54,7 @@
5354
| file://:0:0:0:0 | explicit | Other |
5455
| file://:0:0:0:0 | extern | Other |
5556
| file://:0:0:0:0 | far | Other |
57+
| file://:0:0:0:0 | final | Other |
5658
| file://:0:0:0:0 | float | Other |
5759
| file://:0:0:0:0 | forceinline | Other |
5860
| file://:0:0:0:0 | fp_offset | Other |

0 commit comments

Comments
 (0)