Public static field not const
A static and public field of a
struct or class is not marked as a
const
Since R2022a
Description
This defect occurs when all of these conditions are true:
A class contains a data member that is both
staticandpublicThe
staticandpublicdata member is notconst
Risk
The publicstatic data members of a class can be modified by any of class in the
program. Unless publicstatic data members are specified as const, they might
be modified in unexpected ways and result in bugs that are difficult to diagnose.
Fix
To resolve this defect, specify the public static data members as
const or constexpr.
Examples
Result Information
| Group: Good practice |
| Language: C++ |
| Default: Off |
Command-Line Syntax:
PUBLIC_STATIC_FIELD_NOT_CONST
|
| Impact: Low |
PQL Name:
std.defects.PUBLIC_STATIC_FIELD_NOT_CONST
|
Version History
Introduced in R2022a
See Also
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)