isocpp / isocpp/CppCoreGuidelines
Suggestion for CP.201: Avoid volatile compound operations
Open
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
CP.201 Limit use of volatile variables to loads and stores
Reason
- Compilers don't agree on whether compound operations should be split up, which makes our code less portable. This distinction is very important when working with
volatilememory. - Compound operations other than compound assignment are deprecated for
volatile.
Example
volatile uint32_t counter;
void update()
{
counter++; // bad, is this in-place increment, or a separate read, add, and write?
// the difference matters for volatile access!
auto x = counter; // good, this is always a read, modify, and write
counter = x + 1;
}
Alternative
Create convenience functions for compound volatile operations, and implement them using explicit loads and stores.
Enforcement
Flag compound operations on volatile variables.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test entry point is named. Start by locating the CP.201 guideline and the project's enforcement mechanisms, then determine how compound operations on volatile variables are identified; done means the rule and its enforcement behavior cover the stated cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100