-
Notifications
You must be signed in to change notification settings - Fork 76
Michaelrfairhurst/declarations8 rule 6-2-3 do not duplicate source code #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MichaelRFairhurst
wants to merge
8
commits into
main
Choose a base branch
from
michaelrfairhurst/declarations8-rule-6-2-3-do-not-duplicate-source-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d79cf17
initial implementation of 6-2-3
MichaelRFairhurst fc8fb7e
Finalize firs draft of Rule 6-2-3
MichaelRFairhurst ee92f89
Commit rules.csv changes
MichaelRFairhurst ac06fe8
Remove duplicate name/rule text
MichaelRFairhurst bfdc09a
Handle overloads
MichaelRFairhurst 5a72bef
Fix test formatting
MichaelRFairhurst 8566bb2
Rename SourceCodeImplementedOnlyOnce to handle just inline funcs.
MichaelRFairhurst f450e53
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/dec…
MichaelRFairhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
change_notes/2026-04-19-refactor-nested-anonymous-namespace-logic.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - All queries using `Linkage.qll`: | ||
| - The logic for determining whether a namespace is within an anonymous namespace, directly or indirectly, has been refactored. | ||
| - No visible change in behavior or performance is expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations8.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
|
|
||
| newtype Declarations8Query = | ||
| TSourceCodeImplementedOnlyOnceQuery() or | ||
| TTemplateSpecializationWrongLocationQuery() or | ||
| TDuplicateTypeDefinitionsQuery() | ||
|
|
||
| predicate isDeclarations8QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `sourceCodeImplementedOnlyOnce` query | ||
| Declarations8Package::sourceCodeImplementedOnlyOnceQuery() and | ||
| queryId = | ||
| // `@id` for the `sourceCodeImplementedOnlyOnce` query | ||
| "cpp/misra/source-code-implemented-only-once" and | ||
| ruleId = "RULE-6-2-3" and | ||
| category = "required" | ||
| or | ||
| query = | ||
| // `Query` instance for the `templateSpecializationWrongLocation` query | ||
| Declarations8Package::templateSpecializationWrongLocationQuery() and | ||
| queryId = | ||
| // `@id` for the `templateSpecializationWrongLocation` query | ||
| "cpp/misra/template-specialization-wrong-location" and | ||
| ruleId = "RULE-6-2-3" and | ||
| category = "required" | ||
| or | ||
| query = | ||
| // `Query` instance for the `duplicateTypeDefinitions` query | ||
| Declarations8Package::duplicateTypeDefinitionsQuery() and | ||
| queryId = | ||
| // `@id` for the `duplicateTypeDefinitions` query | ||
| "cpp/misra/duplicate-type-definitions" and | ||
| ruleId = "RULE-6-2-3" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module Declarations8Package { | ||
| Query sourceCodeImplementedOnlyOnceQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `sourceCodeImplementedOnlyOnce` query | ||
| TQueryCPP(TDeclarations8PackageQuery(TSourceCodeImplementedOnlyOnceQuery())) | ||
| } | ||
|
|
||
| Query templateSpecializationWrongLocationQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `templateSpecializationWrongLocation` query | ||
| TQueryCPP(TDeclarations8PackageQuery(TTemplateSpecializationWrongLocationQuery())) | ||
| } | ||
|
|
||
| Query duplicateTypeDefinitionsQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `duplicateTypeDefinitions` query | ||
| TQueryCPP(TDeclarations8PackageQuery(TDuplicateTypeDefinitionsQuery())) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
cpp/misra/src/rules/RULE-6-2-3/DuplicateTypeDefinitions.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * @id cpp/misra/duplicate-type-definitions | ||
| * @name RULE-6-2-3: RULE-6-2-3: Duplicate type definitions across files | ||
| * @description Defining a type with the same fully qualified name in multiple files increases the | ||
| * risk of ODR violations and undefined behavior. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-6-2-3 | ||
| * correctness | ||
| * maintainability | ||
| * scope/system | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
| import codingstandards.cpp.Linkage | ||
|
|
||
| class UserTypeDefinition extends TypeDeclarationEntry { | ||
| UserTypeDefinition() { | ||
| (isDefinition() or getDeclaration() instanceof TypedefType) and | ||
| not getDeclaration().(Class).isAnonymous() and | ||
| not getDeclaration().(Union).isAnonymous() and | ||
| not getDeclaration().(Enum).isAnonymous() and | ||
| not getDeclaration() instanceof ClassTemplateSpecialization and | ||
| not getDeclaration().getNamespace() instanceof WithinAnonymousNamespace | ||
| } | ||
|
|
||
| UserType getUserType() { result = getDeclaration() } | ||
| } | ||
|
|
||
| from UserTypeDefinition t1, UserTypeDefinition t2 | ||
| where | ||
| not isExcluded(t1, Declarations8Package::duplicateTypeDefinitionsQuery()) and | ||
| t1.getUserType().getQualifiedName() = t2.getUserType().getQualifiedName() and | ||
| t1.getFile() != t2.getFile() and | ||
| t1.getFile().getAbsolutePath() < t2.getFile().getAbsolutePath() // Report only once per pair | ||
| select t1, "Type '" + t1.getUserType().getQualifiedName() + "' is defined in files $@ and $@.", t1, | ||
| t1.getFile().getBaseName(), t2, t2.getFile().getBaseName() | ||
39 changes: 39 additions & 0 deletions
39
cpp/misra/src/rules/RULE-6-2-3/SourceCodeImplementedOnlyOnce.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * @id cpp/misra/source-code-implemented-only-once | ||
| * @name RULE-6-2-3: The source code used to implement an entity shall appear only once | ||
| * @description Implementing an entity in multiple source locations increases the risk of ODR | ||
| * violations and undefined behavior. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-6-2-3 | ||
| * correctness | ||
| * maintainability | ||
| * scope/system | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
|
|
||
| predicate isInline(DeclarationEntry d) { | ||
| // There is no way to detect if a `GlobalVariable` is declared inline. | ||
| d.getDeclaration().(Function).isInline() | ||
| } | ||
|
|
||
| from DeclarationEntry d1, DeclarationEntry d2, string namespace, string name | ||
| where | ||
| not isExcluded([d1, d2], Declarations8Package::sourceCodeImplementedOnlyOnceQuery()) and | ||
| d1 != d2 and | ||
| d1.isDefinition() and | ||
| d2.isDefinition() and | ||
| isInline(d1) and | ||
| isInline(d2) and | ||
| d1.getDeclaration().hasQualifiedName(namespace, name) and | ||
| d2.getDeclaration().hasQualifiedName(namespace, name) and | ||
| d1.getFile() != d2.getFile() and | ||
|
MichaelRFairhurst marked this conversation as resolved.
Outdated
|
||
| d1.getFile().getAbsolutePath() < d2.getFile().getAbsolutePath() | ||
| select d1, | ||
| "Inline variable '" + d1.getName() + | ||
| "' is defined in multiple files, violating the source code uniqueness requirement." | ||
40 changes: 40 additions & 0 deletions
40
cpp/misra/src/rules/RULE-6-2-3/TemplateSpecializationWrongLocation.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @id cpp/misra/template-specialization-wrong-location | ||
| * @name RULE-6-2-3: RULE-6-2-3: Template specializations in wrong location | ||
|
MichaelRFairhurst marked this conversation as resolved.
Outdated
|
||
| * @description Template specializations must be defined in the same file as the primary template or | ||
| * where a specialized type is defined to ensure visibility and avoid ODR violations. | ||
| * @kind problem | ||
| * @precision very-high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-6-2-3 | ||
| * correctness | ||
| * maintainability | ||
| * scope/system | ||
| * external/misra/enforcement/decidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
|
|
||
| predicate specializedWithFileDeclaredType(ClassTemplateSpecialization spec) { | ||
| exists(Type argType | | ||
| spec.getTemplateArgument(_).(Type).getUnderlyingType() = argType and | ||
| spec.getFile() = argType.getFile() and | ||
| not argType instanceof TypeTemplateParameter | ||
| ) | ||
| } | ||
|
|
||
| from ClassTemplateSpecialization spec, Class primaryTemplate, File primaryFile | ||
| where | ||
| not isExcluded(spec, Declarations8Package::templateSpecializationWrongLocationQuery()) and | ||
| spec.getPrimaryTemplate() = primaryTemplate and | ||
| primaryFile = primaryTemplate.getFile() and | ||
| // The specialization is in a different file than the primary template | ||
| spec.getFile() != primaryFile and | ||
| // And it's not in the same file as any of its template arguments | ||
| not specializedWithFileDeclaredType(spec) | ||
| select spec, | ||
| "Template specialization '" + spec.getName() + | ||
| "' is declared in a different file than $@ and all specialized template arguments.", | ||
| primaryTemplate, primaryTemplate.getName() | ||
9 changes: 9 additions & 0 deletions
9
cpp/misra/test/rules/RULE-6-2-3/DuplicateTypeDefinitions.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| | test.cpp:15:8:15:22 | definition of StructRedefined | Type 'StructRedefined' is defined in files $@ and $@. | test.cpp:15:8:15:22 | definition of StructRedefined | test.cpp | test2.cpp:16:8:16:22 | definition of StructRedefined | test2.cpp | | ||
| | test.cpp:22:29:22:40 | definition of TplRedefined<T> | Type 'TplRedefined<T>' is defined in files $@ and $@. | test.cpp:22:29:22:40 | definition of TplRedefined<T> | test.cpp | test2.cpp:22:29:22:40 | definition of TplRedefined<T> | test2.cpp | | ||
| | test.cpp:26:6:26:18 | definition of DuplicateEnum | Type 'DuplicateEnum' is defined in files $@ and $@. | test.cpp:26:6:26:18 | definition of DuplicateEnum | test.cpp | test2.cpp:25:6:25:18 | definition of DuplicateEnum | test2.cpp | | ||
| | test.cpp:27:12:27:29 | definition of DuplicateEnumClass | Type 'DuplicateEnumClass' is defined in files $@ and $@. | test.cpp:27:12:27:29 | definition of DuplicateEnumClass | test.cpp | test2.cpp:26:12:26:29 | definition of DuplicateEnumClass | test2.cpp | | ||
| | test.cpp:29:17:29:32 | declaration of DuplicateTypedef | Type 'DuplicateTypedef' is defined in files $@ and $@. | test.cpp:29:17:29:32 | declaration of DuplicateTypedef | test.cpp | test2.cpp:28:17:28:32 | declaration of DuplicateTypedef | test2.cpp | | ||
| | test.cpp:30:7:30:20 | declaration of DuplicateUsing | Type 'DuplicateUsing' is defined in files $@ and $@. | test.cpp:30:7:30:20 | declaration of DuplicateUsing | test.cpp | test2.cpp:29:7:29:20 | declaration of DuplicateUsing | test2.cpp | | ||
| | test.cpp:31:7:31:20 | definition of DuplicateUnion | Type 'DuplicateUnion' is defined in files $@ and $@. | test.cpp:31:7:31:20 | definition of DuplicateUnion | test.cpp | test2.cpp:30:7:30:20 | definition of DuplicateUnion | test2.cpp | | ||
| | test.cpp:36:7:36:11 | definition of Outer | Type 'ns1::Outer' is defined in files $@ and $@. | test.cpp:36:7:36:11 | definition of Outer | test.cpp | test2.cpp:35:7:35:11 | definition of Outer | test2.cpp | | ||
| | test.cpp:37:9:37:13 | definition of Inner | Type 'ns1::Outer::Inner' is defined in files $@ and $@. | test.cpp:37:9:37:13 | definition of Inner | test.cpp | test2.cpp:36:9:36:13 | definition of Inner | test2.cpp | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-6-2-3/DuplicateTypeDefinitions.ql |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-6-2-3/SourceCodeImplementedOnlyOnce.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | test.cpp:6:13:6:26 | definition of func_redefined | Inline variable 'func_redefined' is defined in multiple files, violating the source code uniqueness requirement. | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-6-2-3/SourceCodeImplementedOnlyOnce.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-6-2-3/SourceCodeImplementedOnlyOnce.ql |
14 changes: 14 additions & 0 deletions
14
cpp/misra/test/rules/RULE-6-2-3/TemplateSpecializationWrongLocation.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| | noncompliant_specialization.h:3:19:3:28 | Tpl1<long> | Template specialization 'Tpl1<long>' is declared in a different file than $@ and all specialized template arguments. | template.h:10:29:10:32 | Tpl1<T> | Tpl1<T> | | ||
| | noncompliant_specialization.h:4:19:4:38 | Tpl1<C2> | Template specialization 'Tpl1<C2>' is declared in a different file than $@ and all specialized template arguments. | template.h:10:29:10:32 | Tpl1<T> | Tpl1<T> | | ||
| | noncompliant_specialization.h:5:19:5:35 | Tpl1<C2> | Template specialization 'Tpl1<C2>' is declared in a different file than $@ and all specialized template arguments. | template.h:10:29:10:32 | Tpl1<T> | Tpl1<T> | | ||
| | noncompliant_specialization.h:7:19:7:34 | Tpl2<long, long> | Template specialization 'Tpl2<long, long>' is declared in a different file than $@ and all specialized template arguments. | template.h:11:41:11:44 | Tpl2<A, B> | Tpl2<A, B> | | ||
| | noncompliant_specialization.h:8:19:8:54 | Tpl2<C2, C2> | Template specialization 'Tpl2<C2, C2>' is declared in a different file than $@ and all specialized template arguments. | template.h:11:41:11:44 | Tpl2<A, B> | Tpl2<A, B> | | ||
| | noncompliant_specialization.h:9:19:9:48 | Tpl2<C2, C2> | Template specialization 'Tpl2<C2, C2>' is declared in a different file than $@ and all specialized template arguments. | template.h:11:41:11:44 | Tpl2<A, B> | Tpl2<A, B> | | ||
| | noncompliant_specialization.h:11:29:11:41 | Tpl2<long, T> | Template specialization 'Tpl2<long, T>' is declared in a different file than $@ and all specialized template arguments. | template.h:11:41:11:44 | Tpl2<A, B> | Tpl2<A, B> | | ||
| | noncompliant_specialization.h:12:29:12:48 | Tpl2<C1, T> | Template specialization 'Tpl2<C1, T>' is declared in a different file than $@ and all specialized template arguments. | template.h:11:41:11:44 | Tpl2<A, B> | Tpl2<A, B> | | ||
| | noncompliant_specialization.h:14:19:14:25 | Tpl3<1> | Template specialization 'Tpl3<1>' is declared in a different file than $@ and all specialized template arguments. | template.h:12:22:12:25 | Tpl3<<unnamed>> | Tpl3<<unnamed>> | | ||
| | noncompliant_specialization.h:15:19:15:31 | Tpl4<long, 0> | Template specialization 'Tpl4<long, 0>' is declared in a different file than $@ and all specialized template arguments. | template.h:13:34:13:37 | Tpl4<T, <unnamed>> | Tpl4<T, <unnamed>> | | ||
| | noncompliant_specialization.h:16:19:16:41 | Tpl4<C1, 1> | Template specialization 'Tpl4<C1, 1>' is declared in a different file than $@ and all specialized template arguments. | template.h:13:34:13:37 | Tpl4<T, <unnamed>> | Tpl4<T, <unnamed>> | | ||
| | noncompliant_specialization.h:17:19:17:38 | Tpl4<C1, 1> | Template specialization 'Tpl4<C1, 1>' is declared in a different file than $@ and all specialized template arguments. | template.h:13:34:13:37 | Tpl4<T, <unnamed>> | Tpl4<T, <unnamed>> | | ||
| | noncompliant_specialization.h:18:24:18:43 | Tpl4<C2, N> | Template specialization 'Tpl4<C2, N>' is declared in a different file than $@ and all specialized template arguments. | template.h:13:34:13:37 | Tpl4<T, <unnamed>> | Tpl4<T, <unnamed>> | | ||
| | noncompliant_specialization.h:19:29:19:38 | Tpl4<T, 2> | Template specialization 'Tpl4<T, 2>' is declared in a different file than $@ and all specialized template arguments. | template.h:13:34:13:37 | Tpl4<T, <unnamed>> | Tpl4<T, <unnamed>> | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-6-2-3/TemplateSpecializationWrongLocation.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rules/RULE-6-2-3/TemplateSpecializationWrongLocation.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #ifndef CLASS_H | ||
| #define CLASS_H | ||
|
|
||
| namespace class_h { | ||
| class C1 {}; | ||
| class C2 {}; | ||
| } // namespace class_h | ||
|
|
||
| #endif // CLASS_H |
17 changes: 17 additions & 0 deletions
17
cpp/misra/test/rules/RULE-6-2-3/compliant_specialization.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "class.h" | ||
| #include "template.h" | ||
|
|
||
| namespace compliant_h { | ||
| class C1 {}; | ||
| } // namespace compliant_h | ||
|
|
||
| template <> class Tpl1<compliant_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl2<compliant_h::C1, compliant_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl2<template_h::C1, compliant_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl2<class_h::C1, compliant_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl2<compliant_h::C1, long> {}; // COMPLIANT | ||
|
|
||
| template <typename T> class Tpl2<T, compliant_h::C1> {}; // COMPLIANT | ||
|
|
||
| template<> class Tpl4<compliant_h::C1, 0> {}; // COMPLIANT | ||
| template<int N> class Tpl4<compliant_h::C1, N> {}; // COMPLIANT |
19 changes: 19 additions & 0 deletions
19
cpp/misra/test/rules/RULE-6-2-3/noncompliant_specialization.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "template.h" | ||
|
|
||
| template <> class Tpl1<long> {}; // NON_COMPLIANT | ||
| template <> class Tpl1<template_h::C2> {}; // NON_COMPLIANT | ||
| template <> class Tpl1<class_h::C2> {}; // NON_COMPLIANT | ||
|
|
||
| template <> class Tpl2<long, long> {}; // NON_COMPLIANT | ||
| template <> class Tpl2<template_h::C2, template_h::C2> {}; // NON_COMPLIANT | ||
| template <> class Tpl2<class_h::C2, class_h::C2> {}; // NON_COMPLIANT | ||
|
|
||
| template <typename T> class Tpl2<long, T> {}; // NON_COMPLIANT | ||
| template <typename T> class Tpl2<class_h::C1, T> {}; // NON_COMPLIANT | ||
|
|
||
| template <> class Tpl3<1> {}; // NON_COMPLIANT | ||
| template <> class Tpl4<long, 0> {}; // NON_COMPLIANT | ||
| template <> class Tpl4<template_h::C1, 1> {}; // NON_COMPLIANT | ||
| template <> class Tpl4<class_h::C1, 1> {}; // NON_COMPLIANT | ||
| template <int N> class Tpl4<class_h::C2, N> {}; // NON_COMPLIANT | ||
| template <typename T> class Tpl4<T, 2> {}; // NON_COMPLIANT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef TEMPLATE_H | ||
| #define TEMPLATE_H | ||
| #include "class.h" | ||
|
|
||
| namespace template_h { | ||
| class C1 {}; | ||
| class C2 {}; | ||
| } // namespace template_h | ||
|
|
||
| template <typename T> class Tpl1 {}; | ||
| template <typename A, typename B> class Tpl2 {}; | ||
| template <int> class Tpl3 {}; | ||
| template <typename T, int> class Tpl4 {}; | ||
|
|
||
| template <> class Tpl1<int> {}; // COMPLIANT | ||
| template <> class Tpl1<template_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl1<class_h::C1> {}; // COMPLIANT | ||
|
|
||
| template <> class Tpl2<int, int> {}; // COMPLIANT | ||
| template <> class Tpl2<template_h::C1, template_h::C1> {}; // COMPLIANT | ||
| template <> class Tpl2<class_h::C1, class_h::C1> {}; // COMPLIANT | ||
|
|
||
| template <typename T> class Tpl2<int, T> {}; // COMPLIANT | ||
|
|
||
| template<> class Tpl3<0> {}; // COMPLIANT | ||
| template<> class Tpl4<int, 0> {}; // COMPLIANT | ||
| template<> class Tpl4<template_h::C1, 0> {}; // COMPLIANT | ||
| template<> class Tpl4<class_h::C1, 0> {}; // COMPLIANT | ||
|
|
||
| #endif // TEMPLATE_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.