GeezerVison is showing github.com — C++: fix implicit this · github/codeql@fe89174
File treeExpand file treeCollapse file tree Open diff view settings implementation/raw/internal
Architecture/Refactoring Opportunities
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/external/ExternalArtifact.qll +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ class ExternalData extends @externalDataElement { | 15 | 15 | * Gets the path of the file this data was loaded from, with its | 16 | 16 | * extension replaced by `.ql`. | 17 | 17 | */ | 18 | | - string getQueryPath() { result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") } | | 18 | + string getQueryPath() { result = this.getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") } | 19 | 19 |
| 20 | 20 | /** Gets the number of fields in this data item. */ | 21 | 21 | int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) } | @@ -24,22 +24,22 @@ class ExternalData extends @externalDataElement { | 24 | 24 | string getField(int i) { externalData(this, _, i, result) } | 25 | 25 |
| 26 | 26 | /** Gets the integer value of the `i`th field of this data item. */ | 27 | | - int getFieldAsInt(int i) { result = getField(i).toInt() } | | 27 | + int getFieldAsInt(int i) { result = this.getField(i).toInt() } | 28 | 28 |
| 29 | 29 | /** Gets the floating-point value of the `i`th field of this data item. */ | 30 | | - float getFieldAsFloat(int i) { result = getField(i).toFloat() } | | 30 | + float getFieldAsFloat(int i) { result = this.getField(i).toFloat() } | 31 | 31 |
| 32 | 32 | /** Gets the value of the `i`th field of this data item, interpreted as a date. */ | 33 | | - date getFieldAsDate(int i) { result = getField(i).toDate() } | | 33 | + date getFieldAsDate(int i) { result = this.getField(i).toDate() } | 34 | 34 |
| 35 | 35 | /** Gets a textual representation of this data item. */ | 36 | | - string toString() { result = getQueryPath() + ": " + buildTupleString(0) } | | 36 | + string toString() { result = this.getQueryPath() + ": " + this.buildTupleString(0) } | 37 | 37 |
| 38 | 38 | /** Gets a textual representation of this data item, starting with the `n`th field. */ | 39 | 39 | private string buildTupleString(int n) { | 40 | | - n = getNumFields() - 1 and result = getField(n) | | 40 | + n = this.getNumFields() - 1 and result = this.getField(n) | 41 | 41 | or | 42 | | - n < getNumFields() - 1 and result = getField(n) + "," + buildTupleString(n + 1) | | 42 | + n < this.getNumFields() - 1 and result = this.getField(n) + "," + this.buildTupleString(n + 1) | 43 | 43 | } | 44 | 44 | } | 45 | 45 |
| @@ -53,8 +53,8 @@ class DefectExternalData extends ExternalData { | 53 | 53 | } | 54 | 54 |
| 55 | 55 | /** Gets the URL associated with this data item. */ | 56 | | - string getURL() { result = getField(0) } | | 56 | + string getURL() { result = this.getField(0) } | 57 | 57 |
| 58 | 58 | /** Gets the message associated with this data item. */ | 59 | | - string getMessage() { result = getField(1) } | | 59 | + string getMessage() { result = this.getField(1) } | 60 | 60 | } |
Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/Class.qll +15-15Lines changed: 15 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -269,13 +269,13 @@ class Class extends UserType { | 269 | 269 | * DEPRECATED: name changed to `hasImplicitCopyConstructor` to reflect that | 270 | 270 | * `= default` members are no longer included. | 271 | 271 | */ | 272 | | - deprecated predicate hasGeneratedCopyConstructor() { hasImplicitCopyConstructor() } | | 272 | + deprecated predicate hasGeneratedCopyConstructor() { this.hasImplicitCopyConstructor() } | 273 | 273 |
| 274 | 274 | /** | 275 | 275 | * DEPRECATED: name changed to `hasImplicitCopyAssignmentOperator` to | 276 | 276 | * reflect that `= default` members are no longer included. | 277 | 277 | */ | 278 | | - deprecated predicate hasGeneratedCopyAssignmentOperator() { hasImplicitCopyConstructor() } | | 278 | + deprecated predicate hasGeneratedCopyAssignmentOperator() { this.hasImplicitCopyConstructor() } | 279 | 279 |
| 280 | 280 | /** | 281 | 281 | * Holds if this class, struct or union has an implicitly-declared copy | @@ -487,7 +487,7 @@ class Class extends UserType { | 487 | 487 | exists(ClassDerivation cd | | 488 | 488 | // Add the offset of the direct base class and the offset of `baseClass` | 489 | 489 | // within that direct base class. | 490 | | - cd = getADerivation() and | | 490 | + cd = this.getADerivation() and | 491 | 491 | result = cd.getBaseClass().getANonVirtualBaseClassByteOffset(baseClass) + cd.getByteOffset() | 492 | 492 | ) | 493 | 493 | } | @@ -502,12 +502,12 @@ class Class extends UserType { | 502 | 502 | */ | 503 | 503 | int getABaseClassByteOffset(Class baseClass) { | 504 | 504 | // Handle the non-virtual case. | 505 | | - result = getANonVirtualBaseClassByteOffset(baseClass) | | 505 | + result = this.getANonVirtualBaseClassByteOffset(baseClass) | 506 | 506 | or | 507 | 507 | exists(Class virtualBaseClass, int virtualBaseOffset, int offsetFromVirtualBase | | 508 | 508 | // Look for the base class as a non-virtual base of a direct or indirect | 509 | 509 | // virtual base, adding the two offsets. | 510 | | - getVirtualBaseClassByteOffset(virtualBaseClass) = virtualBaseOffset and | | 510 | + this.getVirtualBaseClassByteOffset(virtualBaseClass) = virtualBaseOffset and | 511 | 511 | offsetFromVirtualBase = virtualBaseClass.getANonVirtualBaseClassByteOffset(baseClass) and | 512 | 512 | result = virtualBaseOffset + offsetFromVirtualBase | 513 | 513 | ) | @@ -623,11 +623,11 @@ class Class extends UserType { | 623 | 623 | * inherits one). | 624 | 624 | */ | 625 | 625 | predicate isPolymorphic() { | 626 | | - exists(MemberFunction f | f.getDeclaringType() = getABaseClass*() and f.isVirtual()) | | 626 | + exists(MemberFunction f | f.getDeclaringType() = this.getABaseClass*() and f.isVirtual()) | 627 | 627 | } | 628 | 628 |
| 629 | 629 | override predicate involvesTemplateParameter() { | 630 | | - getATemplateArgument().(Type).involvesTemplateParameter() | | 630 | + this.getATemplateArgument().(Type).involvesTemplateParameter() | 631 | 631 | } | 632 | 632 |
| 633 | 633 | /** Holds if this class, struct or union was declared 'final'. */ | @@ -765,7 +765,7 @@ class ClassDerivation extends Locatable, @derivation { | 765 | 765 | * }; | 766 | 766 | * ``` | 767 | 767 | */ | 768 | | - Class getBaseClass() { result = getBaseType().getUnderlyingType() } | | 768 | + Class getBaseClass() { result = this.getBaseType().getUnderlyingType() } | 769 | 769 |
| 770 | 770 | override string getAPrimaryQlClass() { result = "ClassDerivation" } | 771 | 771 |
| @@ -818,7 +818,7 @@ class ClassDerivation extends Locatable, @derivation { | 818 | 818 | predicate hasSpecifier(string s) { this.getASpecifier().hasName(s) } | 819 | 819 |
| 820 | 820 | /** Holds if the derivation is for a virtual base class. */ | 821 | | - predicate isVirtual() { hasSpecifier("virtual") } | | 821 | + predicate isVirtual() { this.hasSpecifier("virtual") } | 822 | 822 |
| 823 | 823 | /** Gets the location of the derivation. */ | 824 | 824 | override Location getLocation() { derivations(underlyingElement(this), _, _, _, result) } | @@ -846,7 +846,7 @@ class ClassDerivation extends Locatable, @derivation { | 846 | 846 | * ``` | 847 | 847 | */ | 848 | 848 | class LocalClass extends Class { | 849 | | - LocalClass() { isLocal() } | | 849 | + LocalClass() { this.isLocal() } | 850 | 850 |
| 851 | 851 | override string getAPrimaryQlClass() { not this instanceof LocalStruct and result = "LocalClass" } | 852 | 852 |
| @@ -989,9 +989,9 @@ class ClassTemplateSpecialization extends Class { | 989 | 989 | TemplateClass getPrimaryTemplate() { | 990 | 990 | // Ignoring template arguments, the primary template has the same name | 991 | 991 | // as each of its specializations. | 992 | | - result.getSimpleName() = getSimpleName() and | | 992 | + result.getSimpleName() = this.getSimpleName() and | 993 | 993 | // It is in the same namespace as its specializations. | 994 | | - result.getNamespace() = getNamespace() and | | 994 | + result.getNamespace() = this.getNamespace() and | 995 | 995 | // It is distinguished by the fact that each of its template arguments | 996 | 996 | // is a distinct template parameter. | 997 | 997 | count(TemplateParameter tp | tp = result.getATemplateArgument()) = | @@ -1108,7 +1108,7 @@ deprecated class Interface extends Class { | 1108 | 1108 | * ``` | 1109 | 1109 | */ | 1110 | 1110 | class VirtualClassDerivation extends ClassDerivation { | 1111 | | - VirtualClassDerivation() { hasSpecifier("virtual") } | | 1111 | + VirtualClassDerivation() { this.hasSpecifier("virtual") } | 1112 | 1112 |
| 1113 | 1113 | override string getAPrimaryQlClass() { result = "VirtualClassDerivation" } | 1114 | 1114 | } | @@ -1136,7 +1136,7 @@ class VirtualBaseClass extends Class { | 1136 | 1136 | VirtualClassDerivation getAVirtualDerivation() { result.getBaseClass() = this } | 1137 | 1137 |
| 1138 | 1138 | /** A class/struct that is derived from this one using virtual inheritance. */ | 1139 | | - Class getAVirtuallyDerivedClass() { result = getAVirtualDerivation().getDerivedClass() } | | 1139 | + Class getAVirtuallyDerivedClass() { result = this.getAVirtualDerivation().getDerivedClass() } | 1140 | 1140 | } | 1141 | 1141 |
| 1142 | 1142 | /** | @@ -1155,7 +1155,7 @@ class ProxyClass extends UserType { | 1155 | 1155 | override string getAPrimaryQlClass() { result = "ProxyClass" } | 1156 | 1156 |
| 1157 | 1157 | /** Gets the location of the proxy class. */ | 1158 | | - override Location getLocation() { result = getTemplateParameter().getDefinitionLocation() } | | 1158 | + override Location getLocation() { result = this.getTemplateParameter().getDefinitionLocation() } | 1159 | 1159 |
| 1160 | 1160 | /** Gets the template parameter for which this is the proxy class. */ | 1161 | 1161 | TemplateParameter getTemplateParameter() { | |
Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/Declaration.qll +20-20Lines changed: 20 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -184,7 +184,7 @@ class Declaration extends Locatable, @declaration { | 184 | 184 | predicate hasDefinition() { exists(this.getDefinition()) } | 185 | 185 |
| 186 | 186 | /** DEPRECATED: Use `hasDefinition` instead. */ | 187 | | - predicate isDefined() { hasDefinition() } | | 187 | + predicate isDefined() { this.hasDefinition() } | 188 | 188 |
| 189 | 189 | /** Gets the preferred location of this declaration, if any. */ | 190 | 190 | override Location getLocation() { none() } | @@ -209,7 +209,7 @@ class Declaration extends Locatable, @declaration { | 209 | 209 | predicate isStatic() { this.hasSpecifier("static") } | 210 | 210 |
| 211 | 211 | /** Holds if this declaration is a member of a class/struct/union. */ | 212 | | - predicate isMember() { hasDeclaringType() } | | 212 | + predicate isMember() { this.hasDeclaringType() } | 213 | 213 |
| 214 | 214 | /** Holds if this declaration is a member of a class/struct/union. */ | 215 | 215 | predicate hasDeclaringType() { exists(this.getDeclaringType()) } | @@ -226,14 +226,14 @@ class Declaration extends Locatable, @declaration { | 226 | 226 | * When called on a template, this will return a template parameter type for | 227 | 227 | * both typed and non-typed parameters. | 228 | 228 | */ | 229 | | - final Locatable getATemplateArgument() { result = getTemplateArgument(_) } | | 229 | + final Locatable getATemplateArgument() { result = this.getTemplateArgument(_) } | 230 | 230 |
| 231 | 231 | /** | 232 | 232 | * Gets a template argument used to instantiate this declaration from a template. | 233 | 233 | * When called on a template, this will return a non-typed template | 234 | 234 | * parameter value. | 235 | 235 | */ | 236 | | - final Locatable getATemplateArgumentKind() { result = getTemplateArgumentKind(_) } | | 236 | + final Locatable getATemplateArgumentKind() { result = this.getTemplateArgumentKind(_) } | 237 | 237 |
| 238 | 238 | /** | 239 | 239 | * Gets the `i`th template argument used to instantiate this declaration from a | @@ -252,9 +252,9 @@ class Declaration extends Locatable, @declaration { | 252 | 252 | * `getTemplateArgument(1)` return `1`. | 253 | 253 | */ | 254 | 254 | final Locatable getTemplateArgument(int index) { | 255 | | - if exists(getTemplateArgumentValue(index)) | 256 | | - then result = getTemplateArgumentValue(index) | 257 | | - else result = getTemplateArgumentType(index) | | 255 | + if exists(this.getTemplateArgumentValue(index)) | | 256 | + then result = this.getTemplateArgumentValue(index) | | 257 | + else result = this.getTemplateArgumentType(index) | 258 | 258 | } | 259 | 259 |
| 260 | 260 | /** | @@ -275,13 +275,13 @@ class Declaration extends Locatable, @declaration { | 275 | 275 | * `getTemplateArgumentKind(0)`. | 276 | 276 | */ | 277 | 277 | final Locatable getTemplateArgumentKind(int index) { | 278 | | - exists(getTemplateArgumentValue(index)) and | 279 | | - result = getTemplateArgumentType(index) | | 278 | + exists(this.getTemplateArgumentValue(index)) and | | 279 | + result = this.getTemplateArgumentType(index) | 280 | 280 | } | 281 | 281 |
| 282 | 282 | /** Gets the number of template arguments for this declaration. */ | 283 | 283 | final int getNumberOfTemplateArguments() { | 284 | | - result = count(int i | exists(getTemplateArgument(i))) | | 284 | + result = count(int i | exists(this.getTemplateArgument(i))) | 285 | 285 | } | 286 | 286 |
| 287 | 287 | private Type getTemplateArgumentType(int index) { | @@ -327,9 +327,9 @@ class DeclarationEntry extends Locatable, TDeclarationEntry { | 327 | 327 | * available), or the name declared by this entry otherwise. | 328 | 328 | */ | 329 | 329 | string getCanonicalName() { | 330 | | - if getDeclaration().hasDefinition() | 331 | | - then result = getDeclaration().getDefinition().getName() | 332 | | - else result = getName() | | 330 | + if this.getDeclaration().hasDefinition() | | 331 | + then result = this.getDeclaration().getDefinition().getName() | | 332 | + else result = this.getName() | 333 | 333 | } | 334 | 334 |
| 335 | 335 | /** | @@ -370,18 +370,18 @@ class DeclarationEntry extends Locatable, TDeclarationEntry { | 370 | 370 | /** | 371 | 371 | * Holds if this declaration entry has a specifier with the given name. | 372 | 372 | */ | 373 | | - predicate hasSpecifier(string specifier) { getASpecifier() = specifier } | | 373 | + predicate hasSpecifier(string specifier) { this.getASpecifier() = specifier } | 374 | 374 |
| 375 | 375 | /** Holds if this declaration entry is a definition. */ | 376 | 376 | predicate isDefinition() { none() } // overridden in subclasses | 377 | 377 |
| 378 | 378 | override string toString() { | 379 | | - if isDefinition() | 380 | | - then result = "definition of " + getName() | | 379 | + if this.isDefinition() | | 380 | + then result = "definition of " + this.getName() | 381 | 381 | else | 382 | | - if getName() = getCanonicalName() | 383 | | - then result = "declaration of " + getName() | 384 | | - else result = "declaration of " + getCanonicalName() + " as " + getName() | | 382 | + if this.getName() = this.getCanonicalName() | | 383 | + then result = "declaration of " + this.getName() | | 384 | + else result = "declaration of " + this.getCanonicalName() + " as " + this.getName() | 385 | 385 | } | 386 | 386 | } | 387 | 387 |
| @@ -580,7 +580,7 @@ private class DirectAccessHolder extends Element { | 580 | 580 | // transitive closure with a restricted base case. | 581 | 581 | this.thisCanAccessClassStep(base, derived) | 582 | 582 | or | 583 | | - exists(Class between | thisCanAccessClassTrans(base, between) | | | 583 | + exists(Class between | this.thisCanAccessClassTrans(base, between) | | 584 | 584 | isDirectPublicBaseOf(between, derived) or | 585 | 585 | this.thisCanAccessClassStep(between, derived) | 586 | 586 | ) | |
Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/Element.qll +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,7 +61,7 @@ class ElementBase extends @element { | 61 | 61 | /** | 62 | 62 | * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. | 63 | 63 | */ | 64 | | - final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } | | 64 | + final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") } | 65 | 65 |
| 66 | 66 | /** | 67 | 67 | * Gets the name of a primary CodeQL class to which this element belongs. | @@ -206,9 +206,9 @@ class Element extends ElementBase { | 206 | 206 | /** Gets the closest `Element` enclosing this one. */ | 207 | 207 | cached | 208 | 208 | Element getEnclosingElement() { | 209 | | - result = getEnclosingElementPref() | | 209 | + result = this.getEnclosingElementPref() | 210 | 210 | or | 211 | | - not exists(getEnclosingElementPref()) and | | 211 | + not exists(this.getEnclosingElementPref()) and | 212 | 212 | ( | 213 | 213 | this = result.(Class).getAMember() | 214 | 214 | or | @@ -281,7 +281,7 @@ private predicate isFromUninstantiatedTemplateRec(Element e, Element template) { | 281 | 281 | * ``` | 282 | 282 | */ | 283 | 283 | class StaticAssert extends Locatable, @static_assert { | 284 | | - override string toString() { result = "static_assert(..., \"" + getMessage() + "\")" } | | 284 | + override string toString() { result = "static_assert(..., \"" + this.getMessage() + "\")" } | 285 | 285 |
| 286 | 286 | /** | 287 | 287 | * Gets the expression which this static assertion ensures is true. | |
Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/Enum.qll +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,7 +85,7 @@ class Enum extends UserType, IntegralOrEnumType { | 85 | 85 | * ``` | 86 | 86 | */ | 87 | 87 | class LocalEnum extends Enum { | 88 | | - LocalEnum() { isLocal() } | | 88 | + LocalEnum() { this.isLocal() } | 89 | 89 |
| 90 | 90 | override string getAPrimaryQlClass() { result = "LocalEnum" } | 91 | 91 | } | |
Collapse file Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/File.qll +13-9Lines changed: 13 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,7 @@ class Container extends Locatable, @container { | 52 | 52 | */ | 53 | 53 | string getRelativePath() { | 54 | 54 | exists(string absPath, string pref | | 55 | | - absPath = getAbsolutePath() and sourceLocationPrefix(pref) | | 55 | + absPath = this.getAbsolutePath() and sourceLocationPrefix(pref) | 56 | 56 | | | 57 | 57 | absPath = pref and result = "" | 58 | 58 | or | @@ -79,7 +79,7 @@ class Container extends Locatable, @container { | 79 | 79 | * </table> | 80 | 80 | */ | 81 | 81 | string getBaseName() { | 82 | | - result = getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1) | | 82 | + result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1) | 83 | 83 | } | 84 | 84 |
| 85 | 85 | /** | @@ -105,7 +105,9 @@ class Container extends Locatable, @container { | 105 | 105 | * <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr> | 106 | 106 | * </table> | 107 | 107 | */ | 108 | | - string getExtension() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3) } | | 108 | + string getExtension() { | | 109 | + result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3) | | 110 | + } | 109 | 111 |
| 110 | 112 | /** | 111 | 113 | * Gets the stem of this container, that is, the prefix of its base name up to | @@ -124,7 +126,9 @@ class Container extends Locatable, @container { | 124 | 126 | * <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr> | 125 | 127 | * </table> | 126 | 128 | */ | 127 | | - string getStem() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1) } | | 129 | + string getStem() { | | 130 | + result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1) | | 131 | + } | 128 | 132 |
| 129 | 133 | /** Gets the parent container of this file or folder, if any. */ | 130 | 134 | Container getParentContainer() { | @@ -135,20 +139,20 @@ class Container extends Locatable, @container { | 135 | 139 | Container getAChildContainer() { this = result.getParentContainer() } | 136 | 140 |
| 137 | 141 | /** Gets a file in this container. */ | 138 | | - File getAFile() { result = getAChildContainer() } | | 142 | + File getAFile() { result = this.getAChildContainer() } | 139 | 143 |
| 140 | 144 | /** Gets the file in this container that has the given `baseName`, if any. */ | 141 | 145 | File getFile(string baseName) { | 142 | | - result = getAFile() and | | 146 | + result = this.getAFile() and | 143 | 147 | result.getBaseName() = baseName | 144 | 148 | } | 145 | 149 |
| 146 | 150 | /** Gets a sub-folder in this container. */ | 147 | | - Folder getAFolder() { result = getAChildContainer() } | | 151 | + Folder getAFolder() { result = this.getAChildContainer() } | 148 | 152 |
| 149 | 153 | /** Gets the sub-folder in this container that has the given `baseName`, if any. */ | 150 | 154 | Folder getFolder(string baseName) { | 151 | | - result = getAFolder() and | | 155 | + result = this.getAFolder() and | 152 | 156 | result.getBaseName() = baseName | 153 | 157 | } | 154 | 158 |
| @@ -157,7 +161,7 @@ class Container extends Locatable, @container { | 157 | 161 | * | 158 | 162 | * This is the absolute path of the container. | 159 | 163 | */ | 160 | | - override string toString() { result = getAbsolutePath() } | | 164 | + override string toString() { result = this.getAbsolutePath() } | 161 | 165 | } | 162 | 166 |
| 163 | 167 | /** | |
|