Skip to content
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

A2-7-3: documented type alias to template instantiation considered undocumented #709

Open
fjatWbyT opened this issue Sep 22, 2024 · 2 comments
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@fjatWbyT
Copy link
Contributor

Affected rules

  • A2-7-3

Description

A documented type alias where type-id is a template results in a missing documentation false positive. If the rhs of the (documented) alias declaration does not involve a template, then there is no alert.

Example

/// @brief Template type template_type description.
///
/// @tparam template parameter T.
template<typename T> struct template_type {};

/// @brief Alias to int a_documented_alias.
using a_documented_alias = int;

/// @brief Alias a2_7_3_fp_alias to instantiated template_type with int template parameter.
using a2_7_3_fp_alias = template_type<int>;

Running query UndocumentedUserDefinedType.ql, AUTOSAR A2-7-3, will evaluate to

| declaration of a2_7_3_fp_alias | Declaration entry for user-defined type a2_7_3_fp_alias is missing documentation. |
@fjatWbyT fjatWbyT added the false positive/false negative An issue related to observed false positives or false negatives. label Sep 22, 2024
@fjatWbyT
Copy link
Contributor Author

Hi @lcartey, may I ask whether you have any idea or intuition to the root cause causing this as well as the other similar false positives (e.g. type aliases based on using to templates?
Any pointer into the right direction, perhaps a similar issue related to templates previously solved, would be much appreciated.

@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Oct 15, 2024
@lcartey
Copy link
Collaborator

lcartey commented Oct 23, 2024

The CodeQL extractor for C++ walks the AST to determine which Elements are associated with which comments (accessible from Comment.getCommentedElement()). However, that association is currently not stored in the database for using declarations, due to some complexity around the internal model for using declarations in templates.

The appropriate fix here would likely be to provide a special-cased getCommentedElement(..) for using declarations, that looked at line location. However, this would not be able to determine whether a using declaration generated by a macro was correctly commented, because all the elements generated by a macro have the same location. We could exclude these cases as indeterminable in our current model.

@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Oct 23, 2024
@lcartey lcartey added Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address Impact-Low labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

3 participants