-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Add support for getting literals in using declarations #19603
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
Conversation
ff24105
to
20edf34
Compare
20edf34
to
b322892
Compare
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.
Pull Request Overview
Adds the ability to retrieve the specific member referenced by a using
declaration in a templated base class and updates toString()
to fall back to this new API.
- Introduces
getReferencedMember()
inUsingDeclarationEntry
. - Modifies
toString()
to usegetDeclaration()
first orgetReferencedMember()
as a fallback. - Documents the feature in a new change-notes entry.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
cpp/ql/lib/semmle/code/cpp/Namespace.qll | Added getReferencedMember() and updated toString() |
cpp/ql/lib/change-notes/2025-05-28-using-template.md | Added feature note for getReferencedMember |
Comments suppressed due to low confidence (2)
cpp/ql/lib/semmle/code/cpp/Namespace.qll:191
- The use of
or
between two assignment statements here is invalid syntax and won't produce the intended fallback behavior. Consider computing both descriptions first or use a conditional expression to assign a singleresult
value.
result = "using " + this.getDeclaration().getDescription() or
cpp/ql/lib/semmle/code/cpp/Namespace.qll:192
getReferencedMember()
returns anElement
, not astring
. You need to call its.getDescription()
(or equivalent) to produce a textual representation.
result = "using " + this.getReferencedMember()
237e296
to
d6fbb31
Compare
* class A : public T { | ||
* using T::foo; // `foo` is the member referenced by this using declaration | ||
* }; |
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.
Is it actually relevant that T
is a base class of A
, or would the following also yield a result:
template <typename T>
class A {
using T::foo;
};
d6fbb31
to
79df7b9
Compare
79df7b9
to
770708f
Compare
770708f
to
a0dbe0e
Compare
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.
Some small tweaks of the change note and QLDoc, otherwise LGTM.
* Returns the member referenced by this using declaration when it refers | ||
* to a member of a template type parameter. |
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.
Trying to make it a bit more uniform with the getDeclaration
QLDoc, and using the word "depends", which is what the standard uses:
* Returns the member referenced by this using declaration when it refers | |
* to a member of a template type parameter. | |
* Gets the member that is referenced by this using declaration, where the member depends on a | |
* type template parameter. |
* ``` | ||
* template <typename T> | ||
* class A { | ||
* using T::foo; // `foo` is the member referenced by this using declaration |
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.
I would just omit the comment here, as you effectively explain this below.
* using T::foo; // `foo` is the member referenced by this using declaration | |
* using T::m; |
* `getReferencedMember()` returns the member `foo` declared within the | ||
* template type parameter `T`. |
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.
* `getReferencedMember()` returns the member `foo` declared within the | |
* template type parameter `T`. | |
* Here, `getReferencedMember()` yields the member `m` of `T`. Observe that, as `T` is not instantiated, `m` represented by a `Literal` and not a `Declaration`. |
--- | ||
category: feature | ||
--- | ||
* Added `getReferencedMember` to extract the member referenced by a `using` declaration in a templated base class. |
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.
* Added `getReferencedMember` to extract the member referenced by a `using` declaration in a templated base class. | |
* Added a predicate `getReferencedMember` to `UsingDeclarationEntry`, which yields a member depending on a type template parameter. |
a0dbe0e
to
39469a2
Compare
39469a2
to
10fb806
Compare
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.
LGTM
No description provided.