|
![]() Click on image to see enlargment |
|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home bug1561.cpp
This program converts "showers" into "flowers" which might be nice but since "showers" was initially const how was const integrity shattered? bug1561.cpp lint Output
--- Module: bug1561.cpp
_
h( p );
bug1561.cpp(12) : Warning 1561: Reference initialization causes loss of
const/volatile integrity (arg. no. 1)
Reference Manual Explanation
1561 Reference initialization causes loss of const/volatile integrity (Context) --
A reference initialization is resulting in a capability gain that can cause a
loss of const or volatile integrity.
Typically the message is given on initializing a non-const reference with a
const. For example:
void f( int &x );
const int n = 0;
...
f(n);
Here, function f() could assign a value to its argument and thereby modify n,
which is declared to be const.
The message can also be issued when a pointer is initialized. Consider the
following example.
void h( const int *&q );
int *p;
...
h(p);
It might seem that passing a regular (i.e., non-const) pointer to a const int *
could cause no harm. That would be correct if it were not for the reference.
If function h() were to assign a pointer to const to its parameter q then upon
return from the call, p could be used to modify const data.
There are many subtle cases that can boggle the mind. See the commentary to Message 605.
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #795 - March 2004