Skip to content

Commit 7fa9167

Browse files
authored
Merge pull request #18553 from jketema/preprocblock
C++: Update `PreprocBlock.qll` QLDoc and add C++23 test
2 parents f845ac1 + 442dad4 commit 7fa9167

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

cpp/ql/lib/semmle/code/cpp/headers/PreprocBlock.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* This library offers a view of preprocessor branches (`#if`, `#ifdef`,
3-
* `#ifndef`, `#elif` and `#else`) as blocks of code between the opening and
4-
* closing directives, with navigable parent-child relationships to other
5-
* blocks. The main class is `PreprocessorBlock`.
3+
* `#ifndef`, `#elif`, `#elifdef`, `#elifndef`, and `#else`) as blocks of
4+
* code between the opening and closing directives, with navigable
5+
* parent-child relationships to other blocks. The main class is
6+
* `PreprocessorBlock`.
67
*/
78

89
import cpp
@@ -32,10 +33,10 @@ private int getPreprocIndex(PreprocessorBranchDirective directive) {
3233

3334
/**
3435
* A chunk of code from one preprocessor branch (`#if`, `#ifdef`,
35-
* `#ifndef`, `#elif` or `#else`) to the directive that closes it
36-
* (`#elif`, `#else` or `#endif`). The `getParent()` method
37-
* allows these blocks to be navigated as a tree, with the root
38-
* being the entire file.
36+
* `#ifndef`, `#elif`, `#elifdef`, `#elifndef`, or `#else`) to the
37+
* directive that closes it (`#elif`, `#elifdef`, `#elifndef`, `#else`,
38+
* or `#endif`). The `getParent()` method allows these blocks to be
39+
* navigated as a tree, with the root being the entire file.
3940
*/
4041
class PreprocessorBlock extends @element {
4142
PreprocessorBlock() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
| #elif defined GREEN | preprocblock.cpp:10:0:11:0 | #ifndef BLUE |
22
| #elif defined GREEN | preprocblock.cpp:14:0:15:0 | #if 0 |
33
| #elif defined GREEN | preprocblock.cpp:16:0:17:0 | #else |
4+
| #elifdef GREEN | preprocblock23.cpp:11:0:12:0 | #if 0 |
5+
| #elifdef GREEN | preprocblock23.cpp:13:0:14:0 | #elifndef BLUE |
46
| (no parent) | file://:0:0:0:0 | |
57
| (no parent) | header.h:0:0:8:0 | header.h |
8+
| (no parent) | preprocblock23.cpp:0:0:22:0 | preprocblock23.cpp |
69
| (no parent) | preprocblock.cpp:0:0:25:0 | preprocblock.cpp |
710
| header.h | header.h:3:0:7:0 | #ifndef HEADER_H |
11+
| preprocblock23.cpp | preprocblock23.cpp:7:0:7:0 | #ifdef RED |
12+
| preprocblock23.cpp | preprocblock23.cpp:8:0:17:0 | #elifdef GREEN |
13+
| preprocblock23.cpp | preprocblock23.cpp:18:0:21:0 | #else |
814
| preprocblock.cpp | preprocblock.cpp:6:0:6:0 | #ifdef RED |
915
| preprocblock.cpp | preprocblock.cpp:7:0:20:0 | #elif defined GREEN |
1016
| preprocblock.cpp | preprocblock.cpp:21:0:24:0 | #else |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// preprocblock23.cpp
2+
// semmle-extractor-options: -std=c++23
3+
4+
#include "header.h"
5+
#define GREEN
6+
7+
#ifdef RED
8+
#elifdef GREEN
9+
#include "header.h"
10+
11+
#if 0
12+
#include "header.h" // not reached
13+
#elifndef BLUE
14+
#include "header.h"
15+
#endif
16+
17+
#include "header.h"
18+
#else
19+
20+
// ...
21+
22+
#endif

cpp/ql/test/library-tests/headers/preprocBlock/preprocinclude.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
| preprocblock23.cpp:4:1:4:19 | #include "header.h" | preprocblock23.cpp:0:0:22:0 | preprocblock23.cpp |
2+
| preprocblock23.cpp:9:2:9:20 | #include "header.h" | preprocblock23.cpp:8:0:17:0 | #elifdef GREEN |
3+
| preprocblock23.cpp:14:3:14:21 | #include "header.h" | preprocblock23.cpp:13:0:14:0 | #elifndef BLUE |
4+
| preprocblock23.cpp:17:2:17:20 | #include "header.h" | preprocblock23.cpp:8:0:17:0 | #elifdef GREEN |
15
| preprocblock.cpp:3:1:3:19 | #include "header.h" | preprocblock.cpp:0:0:25:0 | preprocblock.cpp |
26
| preprocblock.cpp:8:2:8:20 | #include "header.h" | preprocblock.cpp:7:0:20:0 | #elif defined GREEN |
37
| preprocblock.cpp:11:3:11:21 | #include "header.h" | preprocblock.cpp:10:0:11:0 | #ifndef BLUE |

0 commit comments

Comments
 (0)