Skip to content

Commit 93a709d

Browse files
committed
Preprocessor6: simplify DIR-4-9
1 parent b10990a commit 93a709d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ import codingstandards.c.misra
1818
import codingstandards.cpp.FunctionLikeMacro
1919
import codingstandards.cpp.Naming
2020

21-
predicate isOperator(string possible) {
22-
possible in [
23-
"+", "-", "*", "/", "%", "^", "&", "|", "~", "!", "=", "<", ">", "+=", "-=", "*=", "/=", "%=",
24-
"^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=", "<=", ">=", "<=>", "&&", "||", "++",
25-
"--", "->*", "->", "()", "[]"
26-
]
27-
}
21+
predicate isOperator(string possible) { possible = any(Operation op).getOperator() }
2822

2923
//cases where we trust the choice
3024
predicate omission(MacroInvocation i) {
@@ -61,6 +55,8 @@ where
6155
not exists(i.getUnexpandedArgument(1)) and
6256
//operator as arg omits function applicability
6357
not isOperator(i.getUnexpandedArgument(_)) and
58+
not exists(Function f | i.getUnexpandedArgument(_) = f.getName()) and
59+
exists(i.getUnexpandedArgument(0).toInt()) and
6460
//static storage duration can only be initialized with constant
6561
not exists(StaticStorageDurationVariable v | i.getExpr() = v.getAnAssignedValue()) and
6662
//function call not allowed in a constant expression (where constant expr is parent)

0 commit comments

Comments
 (0)