Skip to content

Commit 5a07066

Browse files
Fix empty identifier in macros with empty parens
1 parent 2adeaba commit 5a07066

File tree

5 files changed

+311
-305
lines changed

5 files changed

+311
-305
lines changed

change_notes/2025-08-22-fix-variadic-macro-param-names.md

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- "Function-like macros"
2+
- The parameter list of variadic macros previously included the ellipsis in name of the final parameter, potentially leading to incorrect analysis. This has been corrected.
3+
- The parameter list of function-like macros with no parameters (i.e. `MACRO()`) was interpreted in a shared library as having a single parameter with an empty name. This does not seem to have had an impact on any existing queries, but has been fixed to correctly show no parameters.

cpp/common/src/codingstandards/cpp/Macro.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import cpp
22

33
/**
4-
* Macros with a parameter
4+
* Macros with parentheses, e.g. `#define MACRO(x) (x * 2)`.
5+
*
6+
* Note that this includes macros with empty parameter lists, e.g. `#define MACRO() 42`.
57
*/
68
class FunctionLikeMacro extends Macro {
79
FunctionLikeMacro() { this.getHead().regexpMatch("[_a-zA-Z0-9]+\\s*\\([^\\)]*?\\)") }
@@ -12,7 +14,8 @@ class FunctionLikeMacro extends Macro {
1214
.regexpCapture("[_a-zA-Z0-9]+\\s*\\(([^\\)]*)\\)", 1)
1315
.splitAt(",", i)
1416
.trim()
15-
.replaceAll("...", "")
17+
.replaceAll("...", "") and
18+
not result = ""
1619
}
1720

1821
string getAParameter() { result = getParameter(_) }

0 commit comments

Comments
 (0)