`M14-6-1`: enhancement to cover types
还没有人认领这个 Issue。
评估
调研方向
从关联的 issue 192 和 M14-6-1 查询草案开始,包括 NameInDependentBase、TypeUses 和 TemplatesPackage。检查 C++ 示例中展示的 typedef 和类型使用行为,然后确定该查询能否准确覆盖带限定和不带限定的依赖基类 typedef 使用,同时避免旧库的性能问题。
由索引模型根据 Issue 内容生成。
描述
as noted in this issue this rule does not address the types case
the reason was that at the time of writing this query it was discovered that we dont have fully qualified typenames for typedefs:
typedef int TYPE;
template<typename T>
class B {
public:
typedef T TYPE;
};
template<typename T>
class A : B<T> {
public:
void m2(){
TYPE t = 0; // NON_COMPLIANT
::TYPE t1 = 0; //COMPLIANT
typename B<T>::TYPE t2 = 0; // COMPLIANT
}
};
void f(){
A<int> a;
a.m2();
}
example, trying to get full names of types present:
from TypedefType t
select t, t.getQualifiedName(), t.getATypeNameUse()
result:
+| test.cpp:1:13:1:16 | TYPE | TYPE | test.cpp:20:14:20:14 | definition of t |
+| test.cpp:1:13:1:16 | TYPE | TYPE | test.cpp:26:16:26:17 | definition of t1 |
and initial audit level query was written but it was imprecise and used the old lib (so also non performat). would need cleanup or rewriting
/**
* @id cpp/autosar/name-not-referred-using-a-qualified-id-or-this-type-def-type
* @name M14-6-1: In a class template with a dependent base, any typedef type name that may be found in that dependent base shall shall be referred to using a qualified-id or this->
* @description Not using a qualified-id or `this->` syntax for typedef type uses in a class
* template makes the code more difficult to understand.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/autosar/id/m14-6-1
* maintainability
* readability
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.TypeUses
import NameInDependentBase
/**
* `Locatable`s exists only in some `MemberFunction`
* this class is required to speed up `TypeUses.getATypeUse`
*/
class LocatablesInChild extends Locatable {
Class child;
LocatablesInChild() { this.getEnclosingElement() = child.getAMemberFunction() }
predicate isInThisChild(Class c) { c = child }
}
/**
* `TypedefType`s that are declared in a `Class`
* that is a parent of any other `Class`
*/
class ParentTypedefType extends TypedefType {
Class parent;
Class child;
ParentTypedefType() {
this.getDeclaringType() = parent and
getParent(child) = parent
}
predicate thisIsMyChild(Class c) { c = child }
}
/**
* All pairs of `TypedefType` and `ParentTypedefType`
* with a same name
*/
predicate sameNameTypeDefPairs(TypedefType v, ParentTypedefType parentType) {
v.getName() = parentType.getName()
}
from Class c, TypedefType v, ParentTypedefType parentType, LocatablesInChild l
where
not isExcluded(l, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisTypeDefTypeQuery()) and
l.isInThisChild(c) and
parentType.thisIsMyChild(c) and
l = getATypeUse(v) and
//two TypedefTypes with same name but one was declared in the dependent base
sameNameTypeDefPairs(v, parentType)
select l,
"Use of typedef type name that also exists in a base class that may not be fully qualified."
- 主要语言
- CodeQL
- 星标
- 227
- 派生
- 82
- 平均合并
- 6 天 7 小时
- 30 天内合并 PR
- 9
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/codeql-coding-standards 的其他 Issue
-
false positive/false negative Stardard-MISRA-C++
难度 2/5 1-3 小时 新手友好度 72/100
github/codeql-coding-standards#1172 ·
-
Difficulty-Low false positive/false negative false-negative Impact-Low Standard-MISRA-C
难度 2/5 1-3 小时 新手友好度 68/100
-
Difficulty-Medium false positive/false negative false-positive Impact-Medium Standard-CERT-C
难度 4/5 3-5 天 新手友好度 48/100
github/codeql-coding-standards#1200 ·
-
`RULE-0-0-1`: "unreachable statement" false positives due to over-pruning of the control-flow graph 未关闭false positive/false negative
难度 4/5 3-5 天 新手友好度 48/100
github/codeql-coding-standards#1190 ·
-
false positive/false negative
难度 3/5 1-2 天 新手友好度 65/100
github/codeql-coding-standards#1175 ·
查看 github/codeql-coding-standards 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
nightscout/nocturne#1424 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
paritytech/zombienet-sdk#591 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
mruangutai/harness#1897 ·