-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Introduce a new base class for template parameters #18308
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: feature | ||
--- | ||
* A new class `TemplateParameterBase` was introduced, which represents C++ non-type template parameters, type template parameters, and template template parameters. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: deprecated | ||
--- | ||
* The `TemplateParameter` class, representing C++ type template parameters has been deprecated. Use `TypeTemplateParameter` instead. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1666,6 +1666,28 @@ class RoutineType extends Type, @routinetype { | |
} | ||
} | ||
|
||
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++ `typename` (or `class`) template parameter. | ||
* | ||
* DEPRECATED: Use `TypeTemplateParameter` instead. | ||
*/ | ||
deprecated class TemplateParameter = TypeTemplateParameter; | ||
|
||
/** | ||
* A C++ `typename` (or `class`) template parameter. | ||
* | ||
|
@@ -1675,12 +1697,12 @@ class RoutineType extends Type, @routinetype { | |
* class C { }; | ||
* ``` | ||
*/ | ||
class TemplateParameter extends UserType { | ||
TemplateParameter() { | ||
class TypeTemplateParameter extends UserType, TemplateParameterImpl { | ||
TypeTemplateParameter() { | ||
usertypes(underlyingElement(this), _, 7) or usertypes(underlyingElement(this), _, 8) | ||
} | ||
|
||
override string getAPrimaryQlClass() { result = "TemplateParameter" } | ||
override string getAPrimaryQlClass() { result = "TypeTemplateParameter" } | ||
|
||
override predicate involvesTemplateParameter() { any() } | ||
} | ||
|
@@ -1695,7 +1717,7 @@ class TemplateParameter extends UserType { | |
* void foo(const Container<Elem> &value) { } | ||
* ``` | ||
*/ | ||
class TemplateTemplateParameter extends TemplateParameter { | ||
class TemplateTemplateParameter extends TypeTemplateParameter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the description in the change note I thought that type template parameters and template template parameters where to different groups and wouldn't have expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could pull that apart, but that will have quite some fallout in other places, and possibly for customers. So, I prefer to leave this as-is. Another observation is that template template parameters will still refer to (templated) types, so from that perspective it makes sense to have this layering, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks. Let's keep it like this then :) |
||
TemplateTemplateParameter() { usertypes(underlyingElement(this), _, 8) } | ||
|
||
override string getAPrimaryQlClass() { result = "TemplateTemplateParameter" } | ||
|
@@ -1707,7 +1729,7 @@ class TemplateTemplateParameter extends TemplateParameter { | |
* auto val = some_typed_expr(); | ||
* ``` | ||
*/ | ||
class AutoType extends TemplateParameter { | ||
class AutoType extends TypeTemplateParameter { | ||
AutoType() { usertypes(underlyingElement(this), "auto", 7) } | ||
|
||
override string getAPrimaryQlClass() { result = "AutoType" } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| proxy_class.cpp:1:8:1:11 | Base | Struct | | ||
| proxy_class.cpp:3:20:3:20 | T | ProxyClass | | ||
| proxy_class.cpp:3:20:3:20 | T | TemplateParameter | | ||
| proxy_class.cpp:3:20:3:20 | T | TypeTemplateParameter | | ||
| proxy_class.cpp:4:8:4:14 | Derived<Base> | Struct | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this is currently a lie, as nothing represents non-type template parameters. I plan to fix this next.