Re: [Bug c++/25845] want optional warning for non-constant declarations that could be constant

2006-01-18 Thread Gabriel Dos Reis
"sigra at home dot se" <[EMAIL PROTECTED]> writes:

| --- Comment #8 from sigra at home dot se  2006-01-18 19:29 ---
| > On Jan 18, 2006, at 11:19 AM, pcarlini at suse dot de wrote:
| > 
| > > --- Comment #4 from pcarlini at suse dot de  2006-01-18 16:19 
| > > ---
| > > (In reply to comment #3)
| > >> const does nothing when it comes to local variables except for not 
| > >> letting you
| > >> touch it in other expressions.  It does nothing for optimizations or 
| > >> anything
| > >> else.
| > >
| > > This last point is not obvious at all, in my opinion. Why not? In 
| > > principle,
| > > certainly const-ness *can* help optimizers one way or the other. Is 
| > > this just a
| > > current limitation? A design choice? Anything in the standard making 
| > > that
| > > tricky? I would like to know more.
| > 
| > 
| > int f(const int *a, int *b)
| > {
| >*b = 1;
| >return *a;
| > }
| > 
| > a and b can alias and there is no way around that at all because that is
| > what the C++ standard says.
| 
| In this case the compiler should warn because a could be declared "const int *
| const" and b could be declared "int * const".

It does not make any sense to require the compiler to give a warning
in that case. 

-- Gaby


Re: [Bug c++/25845] want optional warning for non-constant declarations that could be constant

2006-01-18 Thread Gabriel Dos Reis
"sigra at home dot se" <[EMAIL PROTECTED]> writes:

|  std::cout << static_cast(t) << std::endl;
| }
| 
| If "static_cast" would work, the compiler should warn.

given call-by-value, you must be joking.

-- Gaby


Re: [Bug c++/25845] want optional warning for non-constant declarations that could be constant

2006-01-18 Thread Andrew Pinski
> > int f(const int *a, int *b)
> > {
> >*b = 1;
> >return *a;
> > }
> > 
> > a and b can alias and there is no way around that at all because that is
> > what the C++ standard says.
> 
> In this case the compiler should warn because a could be declared "const int *
> const" and b could be declared "int * const".

That still does not change the fact that a could point to the same location as
b is pointing too.

-- Pinski


Re: [Bug c++/25845] want optional warning for non-constant declarations that could be constant

2006-01-18 Thread Andrew Pinski


On Jan 18, 2006, at 11:19 AM, pcarlini at suse dot de wrote:

--- Comment #4 from pcarlini at suse dot de  2006-01-18 16:19 
---

(In reply to comment #3)
const does nothing when it comes to local variables except for not 
letting you
touch it in other expressions.  It does nothing for optimizations or 
anything

else.


This last point is not obvious at all, in my opinion. Why not? In 
principle,
certainly const-ness *can* help optimizers one way or the other. Is 
this just a
current limitation? A design choice? Anything in the standard making 
that

tricky? I would like to know more.



int f(const int *a, int *b)
{
  *b = 1;
  return *a;
}

a and b can alias and there is no way around that at all because that is
what the C++ standard says.

-- Pinski