Skip to content

Commit b476450

Browse files
authored
Merge pull request #746 from fjatWbyT/feat-type-member-alias-a14-5-2
`A14-5-2` do not consider type members declared with using aliases.
2 parents 20a3711 + fbfdcae commit b476450

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A14-5-2` - `NonTemplateMemberDefinedInTemplate.ql`
2+
- Fixes #739. Correctly detect template parameters specified in using alias base types, e.g. `using T1 = some_type<T>::Type;`.

cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ where
167167
mf = c.getAMemberFunction() and not mf.isCompilerGenerated() and not exists(mf.getBlock())
168168
)
169169
)
170-
)
170+
) and
171+
// Omit using alias (cf. https://github.com/github/codeql-coding-standards/issues/739)
172+
// Exclude Using alias which refer directly to a TypeParameter
173+
not d.(UsingAliasTypedefType).getBaseType() instanceof TemplateParameter
171174
select d,
172175
"Member " + d.getName() + " template class does not use any of template arguments of its $@.",
173176
d.getDeclaringType(), "declaring type"

cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
| test.cpp:10:9:10:10 | T1 | Member T1 template class does not use any of template arguments of its $@. | test.cpp:6:29:6:30 | C1<T> | declaring type |
21
| test.cpp:11:9:11:10 | T2 | Member T2 template class does not use any of template arguments of its $@. | test.cpp:6:29:6:30 | C1<T> | declaring type |
32
| test.cpp:28:31:28:33 | C12<N> | Member C12<N> template class does not use any of template arguments of its $@. | test.cpp:6:29:6:30 | C1<T> | declaring type |
43
| test.cpp:45:7:45:8 | a1 | Member a1 template class does not use any of template arguments of its $@. | test.cpp:37:31:37:33 | C22<N> | declaring type |

cpp/autosar/test/rules/A14-5-2/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ template <typename T> class C1 {
77
public:
88
enum E1 : T { e1, e2 }; // COMPLIANT
99

10-
using T1 = typename template_base<T>::type; // COMPLIANT[FALSE_POSITIVE]
10+
using T1 = typename template_base<T>::type; // COMPLIANT
1111
using T2 = typename template_base<int>::type; // NON_COMPLIANT
1212

1313
class C11 { // COMPLIANT
@@ -156,4 +156,4 @@ template <J::Type t> class V {
156156
void f4() {
157157
V<J::Type::A> v;
158158
v.type();
159-
}
159+
}

0 commit comments

Comments
 (0)