Main Content
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
static
andpublic
The
static
andpublic
data member is notconst
Risk
The public
static
data members of a class can be modified by any of class in the
program. Unless public
static
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 |
Version History
Introduced in R2022a
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)