From f4626971076b1168253c0e77afbe1f89d4cfaa7c Mon Sep 17 00:00:00 2001 From: Fernando Jose Date: Mon, 14 Oct 2024 10:30:29 +0900 Subject: [PATCH 1/5] feat(a14-5-2): do not consider type members declared with using aliases. --- .../src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql | 4 +++- .../A14-5-2/NonTemplateMemberDefinedInTemplate.expected | 2 -- cpp/autosar/test/rules/A14-5-2/test.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql index 4a81e32b0f..b8dff92ca6 100644 --- a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql +++ b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql @@ -167,7 +167,9 @@ where mf = c.getAMemberFunction() and not mf.isCompilerGenerated() and not exists(mf.getBlock()) ) ) - ) + ) and + // Omit using alias (cf. https://github.com/github/codeql-coding-standards/issues/739) + not d instanceof UsingAliasTypedefType select d, "Member " + d.getName() + " template class does not use any of template arguments of its $@.", d.getDeclaringType(), "declaring type" diff --git a/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected b/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected index d45a3c6871..454a1c6b83 100644 --- a/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected +++ b/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected @@ -1,5 +1,3 @@ -| 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 | declaring type | -| 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 | declaring type | | test.cpp:28:31:28:33 | C12 | Member C12 template class does not use any of template arguments of its $@. | test.cpp:6:29:6:30 | C1 | declaring type | | 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 | declaring type | | test.cpp:46:9:46:10 | a2 | Member a2 template class does not use any of template arguments of its $@. | test.cpp:37:31:37:33 | C22 | declaring type | diff --git a/cpp/autosar/test/rules/A14-5-2/test.cpp b/cpp/autosar/test/rules/A14-5-2/test.cpp index e60a955c68..236f3beb7a 100644 --- a/cpp/autosar/test/rules/A14-5-2/test.cpp +++ b/cpp/autosar/test/rules/A14-5-2/test.cpp @@ -7,8 +7,8 @@ template class C1 { public: enum E1 : T { e1, e2 }; // COMPLIANT - using T1 = typename template_base::type; // COMPLIANT[FALSE_POSITIVE] - using T2 = typename template_base::type; // NON_COMPLIANT + using T1 = typename template_base::type; // COMPLIANT + using T2 = typename template_base::type; // NON_COMPLIANT[FALSE_NEGATIVE] class C11 { // COMPLIANT enum E2 { @@ -156,4 +156,4 @@ template class V { void f4() { V v; v.type(); -} \ No newline at end of file +} From 7e8d2a13dba6d7097f3362899f1aee5548ee55bd Mon Sep 17 00:00:00 2001 From: Fernando Jose Date: Tue, 15 Oct 2024 09:47:52 +0900 Subject: [PATCH 2/5] Add change note. --- change_notes/2024-10-15-fix-fp-739-a14-5-2.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 change_notes/2024-10-15-fix-fp-739-a14-5-2.md diff --git a/change_notes/2024-10-15-fix-fp-739-a14-5-2.md b/change_notes/2024-10-15-fix-fp-739-a14-5-2.md new file mode 100644 index 0000000000..39cb00e3ae --- /dev/null +++ b/change_notes/2024-10-15-fix-fp-739-a14-5-2.md @@ -0,0 +1,2 @@ +- `A14-5-2` - `NonTemplateMemberDefinedInTemplate.ql` + - Fixes #739. Omit type members declared with using aliases. From 327436ce43a632b60edc02a37868cb9a9df30ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9=20=7C=20=EF=BE=8C=EF=BD=AA=EF=BE=99?= =?UTF-8?q?=EF=BE=85=EF=BE=9D=EF=BE=84=EF=BE=9E=20=EF=BE=8E=EF=BD=BE?= Date: Wed, 16 Oct 2024 12:29:34 +0900 Subject: [PATCH 3/5] Update change_notes/2024-10-15-fix-fp-739-a14-5-2.md Co-authored-by: Luke Cartey <5377966+lcartey@users.noreply.github.com> --- change_notes/2024-10-15-fix-fp-739-a14-5-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2024-10-15-fix-fp-739-a14-5-2.md b/change_notes/2024-10-15-fix-fp-739-a14-5-2.md index 39cb00e3ae..6e3f422718 100644 --- a/change_notes/2024-10-15-fix-fp-739-a14-5-2.md +++ b/change_notes/2024-10-15-fix-fp-739-a14-5-2.md @@ -1,2 +1,2 @@ - `A14-5-2` - `NonTemplateMemberDefinedInTemplate.ql` - - Fixes #739. Omit type members declared with using aliases. + - Fixes #739. Correctly detect template parameters specified in using alias base types, e.g. `using T1 = some_type::Type;`. From 5609f092dd4151d6464ea70e5c7d826d43d3d91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9=20=7C=20=EF=BE=8C=EF=BD=AA=EF=BE=99?= =?UTF-8?q?=EF=BE=85=EF=BE=9D=EF=BE=84=EF=BE=9E=20=EF=BE=8E=EF=BD=BE?= Date: Wed, 16 Oct 2024 12:30:10 +0900 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Luke Cartey <5377966+lcartey@users.noreply.github.com> --- .../src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql | 3 ++- cpp/autosar/test/rules/A14-5-2/test.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql index b8dff92ca6..7f9ced9909 100644 --- a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql +++ b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql @@ -169,7 +169,8 @@ where ) ) and // Omit using alias (cf. https://github.com/github/codeql-coding-standards/issues/739) - not d instanceof UsingAliasTypedefType + // Exclude Using alias which refer directly to a TypeParameter + not d.(UsingAliasTypedefType).getBaseType() instanceof TemplateParameter select d, "Member " + d.getName() + " template class does not use any of template arguments of its $@.", d.getDeclaringType(), "declaring type" diff --git a/cpp/autosar/test/rules/A14-5-2/test.cpp b/cpp/autosar/test/rules/A14-5-2/test.cpp index 236f3beb7a..260ff5b4b2 100644 --- a/cpp/autosar/test/rules/A14-5-2/test.cpp +++ b/cpp/autosar/test/rules/A14-5-2/test.cpp @@ -8,7 +8,7 @@ template class C1 { enum E1 : T { e1, e2 }; // COMPLIANT using T1 = typename template_base::type; // COMPLIANT - using T2 = typename template_base::type; // NON_COMPLIANT[FALSE_NEGATIVE] + using T2 = typename template_base::type; // NON_COMPLIANT class C11 { // COMPLIANT enum E2 { From e0b581ae432312715a0341bb99adafd5d7f670b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9=20=7C=20=EF=BE=8C=EF=BD=AA=EF=BE=99?= =?UTF-8?q?=EF=BE=85=EF=BE=9D=EF=BE=84=EF=BE=9E=20=EF=BE=8E=EF=BD=BE?= Date: Wed, 16 Oct 2024 12:33:18 +0900 Subject: [PATCH 5/5] Update NonTemplateMemberDefinedInTemplate.expected --- .../rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected b/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected index 454a1c6b83..f0c78e2af1 100644 --- a/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected +++ b/cpp/autosar/test/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.expected @@ -1,3 +1,4 @@ +| 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 | declaring type | | test.cpp:28:31:28:33 | C12 | Member C12 template class does not use any of template arguments of its $@. | test.cpp:6:29:6:30 | C1 | declaring type | | 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 | declaring type | | test.cpp:46:9:46:10 | a2 | Member a2 template class does not use any of template arguments of its $@. | test.cpp:37:31:37:33 | C22 | declaring type |