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

2006-05-13 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread pinskia at gcc dot gnu dot org
--- 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

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

2006-01-18 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread pinskia at gcc dot gnu dot org
--- 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

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

2006-01-18 Thread pcarlini at suse dot de
--- 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

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

2006-01-18 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread pcarlini at suse dot de
--- 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

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

2006-01-18 Thread pinskia at physics dot uc dot edu
--- 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

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

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

2006-01-18 Thread sigra at home dot se
--- 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

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 *

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

2006-01-18 Thread pinskia at physics dot uc dot edu
--- 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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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_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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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

2006-01-18 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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

2006-01-18 Thread sigra at home dot se
--- 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

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

2006-01-18 Thread gdr at cs dot tamu dot edu
--- 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

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

2006-01-18 Thread pinskia at gcc dot gnu dot org
--- 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