Repository navigation
📝 Add style rule S.3.7: Leave an infinite loop's body empty - #103
Merged
Merged
Conversation
Clang deletes `while (true) { continue; }`: the compiler may assume a
loop without side effects ends, and only an empty body with a constant
condition is exempt (P2809). Polling loops on volatile or atomic memory
can keep `continue;`.
The examples on the home page and in the ADC guide now use an empty
body with the comment inside.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds style rule S.3.7 Leave an infinite loop's body empty, and fixes the two pages whose examples broke it.
Clang deletes
while (true) { continue; }in every standard mode. The compiler may assume that a loop without side effects ends, and only an empty body with a constant condition is exempt (P2809). So a halt loop written that way compiles to nothing, and execution falls into whatever code follows it. GCC keeps the loop.S.3.7
continue;.volatileor atomic memory, such as polling a register or a spin lock, can keepcontinue;. The read is a side effect, so the loop stays. This matches the S.5.4 polling example.{}orcontinuefor an empty loop body. The rule notes that only{}is safe with a constant condition.Pages fixed
index.md: thecatch (...)loop in the examplemain().education/adc.md: the loop in the example terminate handler.Both keep their comment, now inside the empty body. Apart from the rule's own ❌ example, these were the only matches on the site for the pattern in libhal/ci#134.