René's URL Explorer Experiment


Title: Add `Template` query library by jeongsoolee09 · Pull Request #932 · github/codeql-coding-standards · GitHub

Open Graph Title: Add `Template` query library by jeongsoolee09 · Pull Request #932 · github/codeql-coding-standards

X Title: Add `Template` query library by jeongsoolee09 · Pull Request #932 · github/codeql-coding-standards

Description: Description Add a query library titled Template that provides definitions to help reason about templates and human-friendly alert locations. What is this? This library started its life as part of a new version of query for M-0-12 in MISRA C++. The rule was mistaken as pertaining to template usages, and thus the types here was conceived of and utilized to report usages that were thought of violating the rule. Although the definitions were pulled off the final version of the query, these are expected to be of some use in providing sensible alert locations when the pattern a query aims to find involves templates. What does it provide? Templates, when instantiated, become generated code that is only visible after they are processed. This makes tricky when the way the template is instantiated in a particular case has to be reported, and doubly so when there are some other uses of the same template that don't violate the rule. A quick and dirty way is to alert on a location in the uninstantiated template definition, but in practice this makes it tricky to trace back to the client code that instantiates the template in a way that violates the rule. To circumvent this issue, this library provides TemplateInstantiation.getAUse/0 that finds occurrences of a template call in the client code. TemplateInstantiation is a composition of three cases, class templates, function templates, and variable templates. Therefore, it is natural to explain per case the location this predicate gets us for given template instantiation. Class templates Let's assume we're expanding M-0-12, which dictates that explicitly signed or unsigned chars should only be assigned numeric values, to catch template instantiations. We may decide to consider cases like below as below as violating the rule: template class C { public: C() : x(y) {} private: unsigned char x; } void f() { C c1(); C c2(); } The first allocation of c1 does not transgress, as the member x of type unsigned char is assigned to a numeral declared as also having type unsigned char. However, when we allocate c2, the unsigned char member x gets assigned a char literal 'x' with the type char. This can be viewed as violating the rule, and we'd like to report it. But at which location should we report it? We might be tempted to use the member initialization site x(y) as the location to report on. However, it is not immediately clear which allocation between c1 and c2 causes the assignment. Instead, if we choose to alert on the use of C type name on top of the assignment, possibly as a clickable location in the alert message, then it becomes much more helpful for the user to identify the problem. This library enables the first part, to get the type name use, with TemplateInstantiation.getAUse/0. Function templates The story here is not so different from the class templates'. Consider this example: template void g(T y) { unsigned char y = x; } void f() { unsigned char x1 = 1; char x2 = 'x'; g(x1); g(x2); } Only the second call makes a char literal to be assigned to an unsigned char. Again, it is much more helpful when we provide the call site (g(x2)) on top of where the problematic assignment takes place (in the body of g). TemplateInstantiation.getAUse/0 gets the function call g(x2) in the above example. Variable templates Variable template is the most straightforward one out of the three kinds, and the only case where the predicate does not get a different location. This is because instantiation is the use site in the case of variable templates. template T v1; void instantiateTemplateVariables() { v1 = 1; v2 = 'x'; } Given the above example, the predicate gets v2. Call for discussion There are some potential use cases of this library that can enhance result reporting for some queries. The reviewer is recommended to think of ones that might benefit from making use of this library. Change request type Release or process automation (GitHub workflows, internal scripts) Internal documentation External documentation Query files (.ql, .qll, .qls or unit tests) External scripts (analysis report or other code shipped as part of a release) Rules with added or modified queries No rules added Queries have been added for the following rules: rule number here Queries have been modified for the following rules: rule number here Release change checklist A change note (development_handbook.md#change-notes) is required for any pull request which modifies: The structure or layout of the release artifacts. The evaluation performance (memory, execution time) of an existing query. The results of an existing query in any circumstance. If you are only adding new rule queries, a change note is not required. Author: Is a change note required? Yes No 🚨🚨🚨 Reviewer: Confirm that format of shared queries (not the .qll file, the .ql file that imports it) is valid by running them within VS Code. Confirmed Reviewer: Confirm that either a change note is not required or the change note is required and has been added. Confirmed Query development review checklist For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer: Author Have all the relevant rule package description files been checked in? Have you verified that the metadata properties of each new query is set appropriately? Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases? Are the alert messages properly formatted and consistent with the style guide? Have you run the queries on OpenPilot and verified that the performance and results are acceptable?As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process. Does the query have an appropriate level of in-query comments/documentation? Have you considered/identified possible edge cases? Does the query not reinvent features in the standard library? Can the query be simplified further (not golfed!) Reviewer Have all the relevant rule package description files been checked in? Have you verified that the metadata properties of each new query is set appropriately? Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases? Are the alert messages properly formatted and consistent with the style guide? Have you run the queries on OpenPilot and verified that the performance and results are acceptable?As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process. Does the query have an appropriate level of in-query comments/documentation? Have you considered/identified possible edge cases? Does the query not reinvent features in the standard library? Can the query be simplified further (not golfed!)

Open Graph Description: Description Add a query library titled Template that provides definitions to help reason about templates and human-friendly alert locations. What is this? This library started its life as part of a...

X Description: Description Add a query library titled Template that provides definitions to help reason about templates and human-friendly alert locations. What is this? This library started its life as part of a...

Opengraph URL: https://github.com/github/codeql-coding-standards/pull/932

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8c207f52-0249-26b2-863e-78d948e9d1ee
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id96D4:3E9E49:45BC:53B7:6964E653
html-safe-nonce5841d9097c074d10e3a8a351ee163f47fc0228a1e7878061266468fa46249ddb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkQ0OjNFOUU0OTo0NUJDOjUzQjc6Njk2NEU2NTMiLCJ2aXNpdG9yX2lkIjoiMjg3NzY4NjU3ODk1Mjg1NzE3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8361696b98c15a9267df2fb233c6d3f25188eb454feddd63d67f3c7569faf5ce
hovercard-subject-tagpull_request:2668790407
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/github/codeql-coding-standards/pull/932/files
twitter:imagehttps://avatars.githubusercontent.com/u/46663033?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/46663033?s=400&v=4
og:image:altDescription Add a query library titled Template that provides definitions to help reason about templates and human-friendly alert locations. What is this? This library started its life as part of a...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None3c30097417ecb9dfdab6b2e8bc7dc38d73e183d6ad48f94cb69e4a5daa2dbb87
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/github/codeql-coding-standards git https://github.com/github/codeql-coding-standards.git
octolytics-dimension-user_id9919
octolytics-dimension-user_logingithub
octolytics-dimension-repository_id513154248
octolytics-dimension-repository_nwogithub/codeql-coding-standards
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id513154248
octolytics-dimension-repository_network_root_nwogithub/codeql-coding-standards
turbo-body-classeslogged-out env-production page-responsive
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release69fc54a84c74307369dba42af5401200531d116e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/github/codeql-coding-standards/pull/932/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fcodeql-coding-standards%2Fpull%2F932%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgithub%2Fcodeql-coding-standards%2Fpull%2F932%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=github%2Fcodeql-coding-standards
Reloadhttps://github.com/github/codeql-coding-standards/pull/932/files
Reloadhttps://github.com/github/codeql-coding-standards/pull/932/files
Reloadhttps://github.com/github/codeql-coding-standards/pull/932/files
github https://github.com/github
codeql-coding-standardshttps://github.com/github/codeql-coding-standards
Notifications https://github.com/login?return_to=%2Fgithub%2Fcodeql-coding-standards
Fork 72 https://github.com/login?return_to=%2Fgithub%2Fcodeql-coding-standards
Star 181 https://github.com/login?return_to=%2Fgithub%2Fcodeql-coding-standards
Code https://github.com/github/codeql-coding-standards
Issues 104 https://github.com/github/codeql-coding-standards/issues
Pull requests 27 https://github.com/github/codeql-coding-standards/pulls
Actions https://github.com/github/codeql-coding-standards/actions
Projects 1 https://github.com/github/codeql-coding-standards/projects
Models https://github.com/github/codeql-coding-standards/models
Wiki https://github.com/github/codeql-coding-standards/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/github/codeql-coding-standards/security
Please reload this pagehttps://github.com/github/codeql-coding-standards/pull/932/files
Insights https://github.com/github/codeql-coding-standards/pulse
Code https://github.com/github/codeql-coding-standards
Issues https://github.com/github/codeql-coding-standards/issues
Pull requests https://github.com/github/codeql-coding-standards/pulls
Actions https://github.com/github/codeql-coding-standards/actions
Projects https://github.com/github/codeql-coding-standards/projects
Models https://github.com/github/codeql-coding-standards/models
Wiki https://github.com/github/codeql-coding-standards/wiki
Security https://github.com/github/codeql-coding-standards/security
Insights https://github.com/github/codeql-coding-standards/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fgithub%2Fcodeql-coding-standards%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fgithub%2Fcodeql-coding-standards%2Fissues%2Fnew%2Fchoose
jeongsoolee09https://github.com/jeongsoolee09
mainhttps://github.com/github/codeql-coding-standards/tree/main
jeongsoolee09/add-template-libhttps://github.com/github/codeql-coding-standards/tree/jeongsoolee09/add-template-lib
Conversation 0 https://github.com/github/codeql-coding-standards/pull/932
Commits 2 https://github.com/github/codeql-coding-standards/pull/932/commits
Checks 25 https://github.com/github/codeql-coding-standards/pull/932/checks
Files changed https://github.com/github/codeql-coding-standards/pull/932/files
Please reload this pagehttps://github.com/github/codeql-coding-standards/pull/932/files
Add Template query library https://github.com/github/codeql-coding-standards/pull/932/files#top
Show all changes 2 commits https://github.com/github/codeql-coding-standards/pull/932/files
7aaab05 Add first draft of `Template.qll` jeongsoolee09 Jul 15, 2025 https://github.com/github/codeql-coding-standards/pull/932/commits/7aaab05429791c456dd0c475e2e58a360fb806bc
8ff1789 Merge branch 'main' into jeongsoolee09/add-template-lib jeongsoolee09 Jul 15, 2025 https://github.com/github/codeql-coding-standards/pull/932/commits/8ff1789d16de584ef4155d73b725c016a4a3f1a9
Clear filters https://github.com/github/codeql-coding-standards/pull/932/files
Please reload this pagehttps://github.com/github/codeql-coding-standards/pull/932/files
Please reload this pagehttps://github.com/github/codeql-coding-standards/pull/932/files
cpp/common/src/codingstandards/cpp/Template.qllhttps://github.com/github/codeql-coding-standards/pull/932/files#diff-2975c3573d6edd5fde95784f11b3bcad42ff3b0b802b5cc53a4139a8d745e81e
View file https://github.com/github/codeql-coding-standards/blob/8ff1789d16de584ef4155d73b725c016a4a3f1a9/cpp/common/src/codingstandards/cpp/Template.qll
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/github/codeql-coding-standards/pull/932/{{ revealButtonHref }}
Please reload this pagehttps://github.com/github/codeql-coding-standards/pull/932/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.