Skip to content

Update queries after TemplateParameter deprecation #826

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

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c/misra/src/rules/RULE-2-4/UnusedTagDeclaration.ql
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ where
// `isInMacroExpansion` is broken for `UserType`s.
not s.isInMacroExpansion() and
// Exclude template parameters, in case this is run on C++ code.
not s instanceof TemplateParameter
not s instanceof TypeTemplateParameter
select s, "struct " + s.getName() + " has an unused tag."
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import codingstandards.cpp.FunctionEquivalence

class Candidate extends TemplateFunction {
Candidate() {
this.getAParameter().getType().(RValueReferenceType).getBaseType() instanceof TemplateParameter
this.getAParameter().getType().(RValueReferenceType).getBaseType() instanceof
TypeTemplateParameter
}
}

Expand Down
28 changes: 14 additions & 14 deletions cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import codingstandards.cpp.autosar
import codingstandards.cpp.TypeUses
import codingstandards.cpp.Operator

predicate templateDefinitionMentionsTypeParameter(Declaration d, TemplateParameter tp) {
predicate templateDefinitionMentionsTypeParameter(Declaration d, TypeTemplateParameter tp) {
exists(Type t |
(
// direct reference, e.g., fields.
Expand Down Expand Up @@ -50,36 +50,36 @@ predicate templateDefinitionMentionsTypeParameter(Declaration d, TemplateParamet
}

/**
* The set of `TemplateParameter` references within an `Enum`.
* The set of `TypeTemplateParameter` references within an `Enum`.
*/
TemplateParameter enumTemplateReferences(Enum e) {
TypeTemplateParameter enumTemplateReferences(Enum e) {
templateDefinitionMentionsTypeParameter(e.getADeclaration(), result)
or
result = e.getExplicitUnderlyingType()
}

/**
* The set of `TemplateParameter` references within an `Class`.
* The set of `TypeTemplateParameter` references within an `Class`.
*/
TemplateParameter classTemplateReferences(Class c) {
TypeTemplateParameter classTemplateReferences(Class c) {
templateDefinitionMentionsTypeParameter(c.getAMember(), result)
or
c.getADerivation().getBaseType() = result
}

/**
* The set of all of the `TemplateParameter`s referenced by a `EnumConstant`.
* The set of all of the `TypeTemplateParameter`s referenced by a `EnumConstant`.
*/
TemplateParameter enumConstantTemplateReferences(EnumConstant ec) {
TypeTemplateParameter enumConstantTemplateReferences(EnumConstant ec) {
templateDefinitionMentionsTypeParameter(ec.getDeclaringType(), result)
}

/**
* The set of all `TemplateParameter`s referenced by a `Function`.
* The set of all `TypeTemplateParameter`s referenced by a `Function`.
*/
TemplateParameter functionTemplateReferences(Function mf) {
TypeTemplateParameter functionTemplateReferences(Function mf) {
// the type of the function
exists(TemplateParameter tp |
exists(TypeTemplateParameter tp |
result = tp and
(
mf.getType().refersTo(result)
Expand Down Expand Up @@ -115,10 +115,10 @@ TemplateParameter functionTemplateReferences(Function mf) {
}

/**
* The set of all `TemplateParameters` available as arguments to the declaring
* The set of all `TypeTemplateParameters` available as arguments to the declaring
* element of some `Declarations`.
*/
TemplateParameter templateParametersOfDeclaringTemplateClass(Declaration d) {
TypeTemplateParameter templateParametersOfDeclaringTemplateClass(Declaration d) {
result = d.getDeclaringType().getATemplateArgument()
}

Expand Down Expand Up @@ -149,7 +149,7 @@ where
not d instanceof UserNegationOperator and
// for each declaration within a template class get the
// template parameters of the declaring class
not exists(TemplateParameter t |
not exists(TypeTemplateParameter t |
t = templateParametersOfDeclaringTemplateClass(d) and
// and require that the declaration depends on at least
// one of those template parameters.
Expand All @@ -170,7 +170,7 @@ where
) and
// Omit using alias (cf. https://github.com/github/codeql-coding-standards/issues/739)
// Exclude Using alias which refer directly to a TypeParameter
not d.(UsingAliasTypedefType).getBaseType() instanceof TemplateParameter
not d.(UsingAliasTypedefType).getBaseType() instanceof TypeTemplateParameter
select d,
"Member " + d.getName() + " template class does not use any of template arguments of its $@.",
d.getDeclaringType(), "declaring type"
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import codingstandards.cpp.autosar
class NonMemberGenericOperator extends TemplateFunction {
NonMemberGenericOperator() {
this instanceof Operator and
exists(TemplateParameter tp, Type pType |
exists(TypeTemplateParameter tp, Type pType |
pType = getAParameter().getType().getUnspecifiedType() //Parameter Type
|
pType = tp or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UniqueLineStmt extends Locatable {
exists(Declaration d |
this = d.getADeclarationEntry() and
not d instanceof Parameter and
not d instanceof TemplateParameter and
not d instanceof TypeTemplateParameter and
// TODO - Needs to be enhanced to solve issues with
// templated inner classes.
not d instanceof Function and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class TemplateAssignmentOperatorMember extends MemberFunction {
}

/**
* is a copy assigment operator candidate if it has only one param and form in [T, T&, const T&, volatile T&, const volatile T&]
* is a copy assignment operator candidate if it has only one param and form in [T, T&, const T&, volatile T&, const volatile T&]
*/
predicate hasGenericCopyCompatibleParameter() {
exists(TemplateParameter tp, Type pType |
exists(TypeTemplateParameter tp, Type pType |
pType = this.getAParameter().getType().getUnspecifiedType() and //Parameter Type
(
tp = pType //T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from UserType ut, string reason
where
isExcluded(ut, DeadCodePackage::unusedTypeDeclarationsQuery(), reason) and
exists(ut.getFile()) and
not ut instanceof TemplateParameter and
not ut instanceof TypeTemplateParameter and
not ut instanceof ProxyClass and
not exists(getATypeUse(ut)) and
not ut.isFromUninstantiatedTemplate(_)
Expand Down
Loading