-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++: Add
NonTypeTemplateParameter
class
- Loading branch information
Showing
4 changed files
with
99 additions
and
80 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
cpp/ql/lib/change-notes/2024-12-18-non-type-template-parameter.md
This file contains 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,4 @@ | ||
--- | ||
category: feature | ||
--- | ||
* A new class `NonTypeTemplateParameter` was introduced, which represents C++ non-type template parameters. |
This file contains 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
This file contains 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,92 @@ | ||
/** | ||
* Provides a hierarchy of classes for modeling C/C++ template parameters. | ||
*/ | ||
|
||
import semmle.code.cpp.Type | ||
private import semmle.code.cpp.internal.ResolveClass | ||
|
||
abstract private class TemplateParameterImpl extends Locatable { | ||
override string getAPrimaryQlClass() { result = "TemplateParameterImpl" } | ||
} | ||
|
||
/** | ||
* A C++ template parameter. | ||
* | ||
* In the example below, `T`, `TT`, and `I` are template parameters: | ||
* ``` | ||
* template <class T, template<typename> TT, int I> | ||
* class C { }; | ||
* ``` | ||
*/ | ||
final class TemplateParameterBase = TemplateParameterImpl; | ||
|
||
/** | ||
* A C++ non-type template parameter. | ||
* | ||
* In the example below, `I` is a non-type template parameter: | ||
* ``` | ||
* template <int I> | ||
* class C { }; | ||
* ``` | ||
*/ | ||
class NonTypeTemplateParameter extends Literal, TemplateParameterImpl { | ||
NonTypeTemplateParameter() { nontype_template_parameters(underlyingElement(this)) } | ||
|
||
override string getAPrimaryQlClass() { result = "NonTypeTemplateParameter" } | ||
} | ||
|
||
/** | ||
* A C++ `typename` (or `class`) template parameter. | ||
* | ||
* DEPRECATED: Use `TypeTemplateParameter` instead. | ||
*/ | ||
deprecated class TemplateParameter = TypeTemplateParameter; | ||
|
||
/** | ||
* A C++ `typename` (or `class`) template parameter. | ||
* | ||
* In the example below, `T` is a template parameter: | ||
* ``` | ||
* template <class T> | ||
* class C { }; | ||
* ``` | ||
*/ | ||
class TypeTemplateParameter extends UserType, TemplateParameterImpl { | ||
TypeTemplateParameter() { | ||
usertypes(underlyingElement(this), _, 7) or usertypes(underlyingElement(this), _, 8) | ||
} | ||
|
||
override string getAPrimaryQlClass() { result = "TypeTemplateParameter" } | ||
|
||
override predicate involvesTemplateParameter() { any() } | ||
} | ||
|
||
/** | ||
* A C++ template template parameter. | ||
* | ||
* In the example below, `T` is a template template parameter (although its name | ||
* may be omitted): | ||
* ``` | ||
* template <template <typename T> class Container, class Elem> | ||
* void foo(const Container<Elem> &value) { } | ||
* ``` | ||
*/ | ||
class TemplateTemplateParameter extends TypeTemplateParameter { | ||
TemplateTemplateParameter() { usertypes(underlyingElement(this), _, 8) } | ||
|
||
override string getAPrimaryQlClass() { result = "TemplateTemplateParameter" } | ||
} | ||
|
||
/** | ||
* A type representing the use of the C++11 `auto` keyword. | ||
* ``` | ||
* auto val = some_typed_expr(); | ||
* ``` | ||
*/ | ||
class AutoType extends TypeTemplateParameter { | ||
AutoType() { usertypes(underlyingElement(this), "auto", 7) } | ||
|
||
override string getAPrimaryQlClass() { result = "AutoType" } | ||
|
||
override Location getLocation() { result instanceof UnknownDefaultLocation } | ||
} |
This file contains 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