AutosarC++19_03-A2.11.1¶
Volatile keyword shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | design / implementation |
| Enforcement | automated |
Rationale
The volatile keyword disables compiler optimizations for a particular variable or object’s value in case those values may change in ways not specified by the language (e.g.
object representing a hardware register). It is error prone and often misused by developers, as they expect this is equal to variable or object’s value being atomic.
Note: The main intention of this rule is to eliminate incorrect usages of volatile keyword and force developers to precisely document each usage of volatile keyword.
See Also
- JSF December 2005 [8]: AV Rule 205: The volatile keyword shall not be used unless directly interfacing with hardware.
- HIC++ v4.0 [9]: 18.2.3: Do not share volatile data between threads.
- C++ Core Guidelines [11]: CP.8: Don’t try to use volatile for synchronization.
- C++ Core Guidelines [11]: CP.200: Use volatile only to talk to non-C++ memory.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
volatile_qualifier |
The volatile type qualifier shall not be used |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.