Von: "Jonathan Wakely" <jwakely....@gmail.com>

 > What exactly are you suggesting for the semantics of the warning? 

Good question. It is difficult to detect all suspiscious cases, but at least 
some of the can be defined:

If we have a function prototype 

f(...,Ti xi,...Tj xj,...)

and call the function f(... xi, ... xj,...) with some xi, xj with aliasing / 
data sharing,

and both Ti and Tj are references/pointers and at least one is a non-const 
pointer / reference,
then the warning should be given.

E.g. for both int:

Ti int: no warning
Ti int& or int*: warning if Tj is int*, const int*, int&, or const int&; no 
warning for Tj int.
Ti const int& or const int*: warning if Tj is int*, or int&; no warning if Tj 
is const int*, const int&, or int. 

Or maybe some code example:

void increase_x_by_y_and_z(int& x, const int& y, const int& z)
{
  x+=y;
  x+=z;
}

This should be OK (no sharing, no warning):

x=1;
y=1;
z=1;

increase_x_by_y_and_z(x,y,z);

This should give a warning (sharing of int& and const int&):

x=1;
y=1;

increase_x_by_y_and_z(x,y,x);

On the other hand, this is OK (y is shared but not mutable - two times const 
int&):

x=1;
y=1;

increase_x_by_y_and_z(x,y,y);


Helmut



Reply via email to