--- Comment #20 from sigra at home dot se 2006-05-13 08:44 ---
I see that the feature I asked for has been implemented in the Ada frontend of
GCC. This program:
with Ada.Text_IO; use Ada.Text_IO;
procedure Prov is
A : Natural := 0;
begin
Put_Line (A = A'Img);
end Prov;
compiled
--- Comment #1 from pinskia at gcc dot gnu dot org 2006-01-18 15:36 ---
Can you give an example?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25845
--- Comment #2 from sigra at home dot se 2006-01-18 16:07 ---
Example 1:
{
int i = f();
do_something(i + 1, 7, 'h');
do_something_else(i % 3, 'e');
}
If i could be declared const int, the compiler should warn.
Example 2:
float dra(float m, Panel p) {
p.do_me(5);
return
--- Comment #3 from pinskia at gcc dot gnu dot org 2006-01-18 16:13 ---
I still don't understand what this warning is useful for?
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
--- 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
--- Comment #5 from sigra at home dot se 2006-01-18 16:25 ---
(In reply to comment #3)
I still don't understand what this warning is useful for?
const does nothing when it comes to local variables except for not letting
you touch it in other expressions. It does nothing for
--- Comment #7 from pcarlini at suse dot de 2006-01-18 16:32 ---
(In reply to comment #6)
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.
Interesting example. But
--- Comment #6 from pinskia at gcc dot gnu dot org 2006-01-18 16:29 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
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
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
--- 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
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 *
--- Comment #9 from pinskia at gcc dot gnu dot org 2006-01-18 19:33 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
int f(const int *a, int *b)
{
*b = 1;
return *a;
}
a and b can alias and there is no way around that at
--- Comment #10 from gdr at cs dot tamu dot edu 2006-01-18 20:29 ---
Subject: Re: New: want optional warning for non-constant declarations that
could be constant
sigra at home dot se [EMAIL PROTECTED] writes:
| Declaring variables and parameters as constants is a very useful feature
sigra at home dot se [EMAIL PROTECTED] writes:
| std::cout static_castunsigned short(t) std::endl;
| }
|
| If static_castconst unsigned short would work, the compiler should warn.
given call-by-value, you must be joking.
-- Gaby
--- Comment #11 from gdr at cs dot tamu dot edu 2006-01-18 20:30 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
sigra at home dot se [EMAIL PROTECTED] writes:
| std::cout static_castunsigned short(t) std::endl;
| }
|
| If
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
--- Comment #12 from gdr at cs dot tamu dot edu 2006-01-18 20:33 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
sigra at home dot se [EMAIL PROTECTED] writes:
| --- Comment #8 from sigra at home dot se 2006-01-18 19:29 ---
| On
--- Comment #13 from sigra at home dot se 2006-01-18 20:41 ---
It does not make any sense to require the compiler to give a warning
in that case.
Read the subject again: optional
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25845
--- Comment #14 from sigra at home dot se 2006-01-18 20:49 ---
Isn't this a task for lint-like tool? GCC isn't such thing.
Are you sure? http://directory.fsf.org/GNU/gcc.html says: GCC provides many
levels of source code error checking traditionally provided by other tools
(such as
--- Comment #15 from gdr at cs dot tamu dot edu 2006-01-18 22:35 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
sigra at home dot se [EMAIL PROTECTED] writes:
| It does not make any sense to require the compiler to give a warning
| in
--- Comment #16 from gdr at cs dot tamu dot edu 2006-01-18 22:37 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
sigra at home dot se [EMAIL PROTECTED] writes:
| Isn't this a task for lint-like tool? GCC isn't such thing.
|
| Are you
--- Comment #17 from sigra at home dot se 2006-01-18 23:23 ---
There is some good advice at http://www.gotw.ca/publications/advice98.htm which
says that one should be const-correct and use const whenever possible. (But I
do not suggest using const for return values.) This feature
--- Comment #18 from gdr at cs dot tamu dot edu 2006-01-19 00:09 ---
Subject: Re: want optional warning for non-constant declarations that could be
constant
sigra at home dot se [EMAIL PROTECTED] writes:
| There is some good advice at
that precisely prooves my point: it is a coding
--- Comment #19 from pinskia at gcc dot gnu dot org 2006-01-19 01:00
---
Closing as won't fix based on GDR's comments.
--
pinskia at gcc dot gnu dot org changed:
What|Removed |Added
24 matches
Mail list logo