Skip to content

Commit de0eb9e

Browse files
committed
Improve scope.qll library to handle global classes and align severity tag on RULE-6-2-4 with A3-1-1
1 parent e5da8c9 commit de0eb9e

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

cpp/common/src/codingstandards/cpp/Scope.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ predicate hidesStrict(UserVariable v1, UserVariable v2) {
369369
predicate hasNamespaceScope(Declaration decl) {
370370
// getNamespace always returns a namespace (e.g. the global namespace).
371371
exists(Namespace n | namespacembrs(unresolveElement(n), underlyingElement(decl)))
372+
or
373+
decl.isTopLevel() and
374+
not namespacembrs(_, decl)
372375
}
373376

374377
/** Holds if `decl` has class scope. */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
| test.hpp:3:6:3:7 | definition of f1 | Header file $@ contains function f1 that lead to One Definition Rule violation. | test.hpp:0:0:0:0 | test.hpp | test.hpp |
22
| test.hpp:8:5:8:5 | definition of i | Header file $@ contains object i that lead to One Definition Rule violation. | test.hpp:0:0:0:0 | test.hpp | test.hpp |
33
| test.hpp:9:12:9:13 | definition of i1 | Header file $@ contains object i1 that lead to One Definition Rule violation. | test.hpp:0:0:0:0 | test.hpp | test.hpp |
4+
| test.hpp:23:5:23:8 | definition of m | Header file $@ contains function m that lead to One Definition Rule violation. | test.hpp:0:0:0:0 | test.hpp | test.hpp |
5+
| test.hpp:25:5:25:9 | definition of m1 | Header file $@ contains function m1 that lead to One Definition Rule violation. | test.hpp:0:0:0:0 | test.hpp | test.hpp |

cpp/common/test/rules/violationsofonedefinitionrule/test.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@ class C {
2020
int m1(); // COMPLIANT
2121
};
2222

23-
int C::m() {} // NON_COMPLIANT[FALSE_NEGATIVE] - external linkage library
24-
// issue/namespace of class not found
25-
int C::m1() {} // NON_COMPLIANT[FALSE_NEGATIVE] - external linkage library
26-
// issue/namespace of class not found
23+
int C::m() {} // NON_COMPLIANT
24+
int C::m1() {} // NON_COMPLIANT

cpp/misra/src/rules/RULE-6-2-4/ViolationsOfOneDefinitionRuleMisra.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* behaviour.
77
* @kind problem
88
* @precision very-high
9-
* @problem.severity error
9+
* @problem.severity warning
1010
* @tags external/misra/id/rule-6-2-4
1111
* correctness
1212
* maintainability

rule_packages/cpp/Linkage2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"kind": "problem",
1212
"name": "A header file shall not contain definitions of functions or objects that are non-inline and have external linkage",
1313
"precision": "very-high",
14-
"severity": "error",
14+
"severity": "warning",
1515
"short_name": "ViolationsOfOneDefinitionRuleMisra",
1616
"shared_implementation_short_name": "ViolationsOfOneDefinitionRule",
1717
"tags": [

0 commit comments

Comments
 (0)