-
Notifications
You must be signed in to change notification settings - Fork 76
Initial implementation of rule 4-1-1, must be standard C++17 #1106
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
Merged
MichaelRFairhurst
merged 10 commits into
main
from
michaelrfairhust/toolchain2-be-iso-cpp17-compliant
Apr 17, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
40ed471
Initial implementation of rule 4-1-1, must be standard C++17
MichaelRFairhurst 9271829
Fix selection of std lib result by excluding unwrapped elements
MichaelRFairhurst 8ef8017
Fix & improve tests
MichaelRFairhurst 20b5bf6
fix build failures
MichaelRFairhurst 9b070a0
test case format
MichaelRFairhurst 0441ef7
Apply suggestions from code review
mbaluda 2c2ec86
Adjust formatting of #pragma once directive
mbaluda 9a4bb8b
Fix spelling error in compiler extension warning
mbaluda 634f4b3
Merge branch 'main' into michaelrfairhust/toolchain2-be-iso-cpp17-com…
mbaluda e33289f
Improved messaging
MichaelRFairhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
cpp/common/src/codingstandards/cpp/exclusions/cpp/Toolchain2.qll
This file contains hidden or 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,26 @@ | ||
| //** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
| import cpp | ||
| import RuleMetadata | ||
| import codingstandards.cpp.exclusions.RuleMetadata | ||
|
|
||
| newtype Toolchain2Query = TCompilerLanguageExtensionsUsedQuery() | ||
|
|
||
| predicate isToolchain2QueryMetadata(Query query, string queryId, string ruleId, string category) { | ||
| query = | ||
| // `Query` instance for the `compilerLanguageExtensionsUsed` query | ||
| Toolchain2Package::compilerLanguageExtensionsUsedQuery() and | ||
| queryId = | ||
| // `@id` for the `compilerLanguageExtensionsUsed` query | ||
| "cpp/misra/compiler-language-extensions-used" and | ||
| ruleId = "RULE-4-1-1" and | ||
| category = "required" | ||
| } | ||
|
|
||
| module Toolchain2Package { | ||
| Query compilerLanguageExtensionsUsedQuery() { | ||
| //autogenerate `Query` type | ||
| result = | ||
| // `Query` type for `compilerLanguageExtensionsUsed` query | ||
| TQueryCPP(TToolchain2PackageQuery(TCompilerLanguageExtensionsUsedQuery())) | ||
| } | ||
| } |
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
cpp/misra/src/rules/RULE-4-1-1/CompilerLanguageExtensionsUsed.ql
This file contains hidden or 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,27 @@ | ||
| /** | ||
| * @id cpp/misra/compiler-language-extensions-used | ||
| * @name RULE-4-1-1: A program shall conform to ISO/IEC 14882:2017 (C++17) | ||
| * @description Language extensions are compiler-specific features that are not part of the C++17 | ||
| * standard. Using these extensions reduces portability and may lead to unpredictable | ||
| * behavior when code is compiled with different compilers or compiler versions. | ||
| * @kind problem | ||
| * @precision high | ||
| * @problem.severity error | ||
| * @tags external/misra/id/rule-4-1-1 | ||
| * scope/system | ||
| * maintainability | ||
| * portability | ||
| * external/misra/enforcement/undecidable | ||
| * external/misra/obligation/required | ||
| */ | ||
|
|
||
| import cpp | ||
| import codingstandards.cpp.misra | ||
| import codingstandards.cpp.Extensions | ||
| import codingstandards.cpp.AlertReporting | ||
|
|
||
| from Element unwrapped, CPPCompilerExtension e | ||
| where | ||
| not isExcluded([e, unwrapped], Toolchain2Package::compilerLanguageExtensionsUsedQuery()) and | ||
| unwrapped = MacroUnwrapper<CPPCompilerExtension>::unwrapElement(e) | ||
| select unwrapped, e.getMessage() |
25 changes: 25 additions & 0 deletions
25
cpp/misra/test/rules/RULE-4-1-1/CompilerLanguageExtensionsUsed.expected
This file contains hidden or 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,25 @@ | ||
| | test.cpp:11:3:11:19 | maybe_unused | Use of attribute 'maybe_unused' in namespace 'gnu' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:12:16:12:22 | aligned | Use of attribute 'aligned' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:13:16:13:21 | unused | Use of attribute 'unused' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:14:21:14:28 | noreturn | Use of attribute 'noreturn' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:15:3:15:17 | deprecated | Use of attribute 'deprecated' in namespace 'gnu' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:16:3:16:23 | nonstandard_attribute | Use of unrecognized or non-C++17 attribute 'nonstandard_attribute'. | | ||
| | test.cpp:19:3:19:20 | call to __builtin_popcount | Call to builtin function '__builtin_popcount' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:20:3:20:18 | call to __builtin_expect | Call to builtin function '__builtin_expect' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:21:3:21:22 | call to __sync_fetch_and_add_4 | Call to builtin function '__sync_fetch_and_add_4' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:23:3:23:20 | __is_abstract | Use of built-in operation '__is_abstract' is a compiler extension. | | ||
| | test.cpp:24:3:24:22 | __is_same | Use of built-in operation '__is_same' is a compiler extension. | | ||
| | test.cpp:30:3:33:4 | (statement expression) | Statement expressions are a compiler extension and are not portable to other compilers. | | ||
| | test.cpp:34:3:34:12 | ... ? ... : ... | Ternaries with omitted middle operands are a compiler extension and are not portable to other compilers. | | ||
| | test.cpp:36:12:36:13 | definition of l0 | Declaration of variable 'l0' as type '__int128' requires a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:45:20:45:30 | fallthrough | Use of attribute 'fallthrough' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:47:7:47:22 | fallthrough | Use of attribute 'fallthrough' in namespace 'gnu' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:55:3:55:29 | __builtin_va_start | Use of built-in operation '__builtin_va_start' is a compiler extension. | | ||
| | test.cpp:60:7:60:8 | definition of m1 | Declaration of variable 'm1' as a zero-length array (of 'int') requires a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:64:31:64:41 | vector_size | Use of attribute 'vector_size' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:66:1:66:20 | #ifdef __has_builtin | Call to builtin preprocessor feature '__has_builtin' is a compiler extension and is not portable to other compilers. | | ||
| | test.cpp:72:1:72:12 | #pragma once | Use of non-standard preprocessor directive '#pragma once' is a compiler extension. | | ||
| | test.cpp:73:1:73:27 | #pragma GCC diagnostic push | Use of non-standard preprocessor directive '#pragma GCC diagnostic push' is a compiler extension. | | ||
| | test.cpp:74:1:74:28 | #warning "This is a warning" | Use of non-standard preprocessor directive '#warning' is a compiler extension. | | ||
| | test.cpp:76:1:76:40 | #warning "preceding spaces is common" | Use of non-standard preprocessor directive '#warning' is a compiler extension. | | ||
| | test.cpp:81:7:81:7 | VLA declaration | Variable length array (used in 'VLA declaration') are a compiler extension and are not portable to other compilers. | |
1 change: 1 addition & 0 deletions
1
cpp/misra/test/rules/RULE-4-1-1/CompilerLanguageExtensionsUsed.qlref
This file contains hidden or 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 @@ | ||
| rules/RULE-4-1-1/CompilerLanguageExtensionsUsed.ql |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.