public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* G++/GCC not detetcing stupid errors in code.
@ 2008-05-22  8:56 Laurent Dufréchou
  2008-05-22  9:00 ` Sven Eschenberg
  0 siblings, 1 reply; 10+ messages in thread
From: Laurent Dufréchou @ 2008-05-22  8:56 UTC (permalink / raw)
  To: gcc-help

Hi there,

I’m using g++ for the first time via gcc 4.1.2.
I’ve written a little code (first C++ oriented and because guys with which I
work come from C, it is slightly modified to compile with G++ and gcc)

>>>>>>>>>>>>>>>>>>> Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
//#include <iostream>
#include <stdio.h>

//using namespace std;

int main()

{

                int toto;

                short tata;

                toto = 1111118;

                tata = toto;  //error 1!

                //cout << toto << "tata:" << tata << endl;

                printf("%d %i",toto,tata);

                //return 0; //error 2 because no return

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I i compile with gcc (cc), it detects no int returned error (OK good point)
But the downcast (tata = toto) doesn’t raise any warning!

If I use G++ the downcast is not detected and even more the return is not
also detected (!)

I was thining that Gcc was really strict and I choose it because I was
thinking that, I’m quite disappointed :/
I’ve tried –Wall –Wextra –pedantic + a ton of other switch with no luck…

Do i miss something ? 

How can I put Gcc in “user is stupid I need to check all” mode?


Laurent

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
  2008-05-22  8:56 G++/GCC not detetcing stupid errors in code Laurent Dufréchou
@ 2008-05-22  9:00 ` Sven Eschenberg
  2008-05-22 10:53   ` Laurent Dufrechou
       [not found]   ` <-457754682823264016@unknownmsgid>
  0 siblings, 2 replies; 10+ messages in thread
From: Sven Eschenberg @ 2008-05-22  9:00 UTC (permalink / raw)
  To: Laurent Dufréchou; +Cc: gcc-help

You are looking for -Wconversion I guess.

Implicit conversion are a nice thing to have ;-).

Regards

-Sven


Laurent Dufréchou schrieb:
> Hi there,
>
> IÂ’m using g++ for the first time via gcc 4.1.2.
> IÂ’ve written a little code (first C++ oriented and because guys with which I
> work come from C, it is slightly modified to compile with G++ and gcc)
>
>   
>>>>>>>>>>>>>>>>>>>> Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>                                         
>  
> //#include <iostream>
> #include <stdio.h>
>
> //using namespace std;
>
> int main()
>
> {
>
>                 int toto;
>
>                 short tata;
>
>                 toto = 1111118;
>
>                 tata = toto;  //error 1!
>
>                 //cout << toto << "tata:" << tata << endl;
>
>                 printf("%d %i",toto,tata);
>
>                 //return 0; //error 2 because no return
>
> }
>
>   
>
> I i compile with gcc (cc), it detects no int returned error (OK good point)
> But the downcast (tata = toto) doesnÂ’t raise any warning!
>
> If I use G++ the downcast is not detected and even more the return is not
> also detected (!)
>
> I was thining that Gcc was really strict and I choose it because I was
> thinking that, IÂ’m quite disappointed :/
> I’ve tried –Wall –Wextra –pedantic + a ton of other switch with no luck…
>
> Do i miss something ? 
>
> How can I put Gcc in “user is stupid I need to check all” mode?
>
>
> Laurent
>
>   

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: G++/GCC not detetcing stupid errors in code.
  2008-05-22  9:00 ` Sven Eschenberg
@ 2008-05-22 10:53   ` Laurent Dufrechou
       [not found]   ` <-457754682823264016@unknownmsgid>
  1 sibling, 0 replies; 10+ messages in thread
From: Laurent Dufrechou @ 2008-05-22 10:53 UTC (permalink / raw)
  To: 'Sven Eschenberg', 'Laurent Dufréchou'; +Cc: gcc-help

Arf no... Here is my compile option :)

g++ -march=nocona -Wall -Wfloat-equal -Wshadow -Wpointer-arith -Wcast-align
-Wcast-qual -Wconversion -Wextra -Wreorder -Wold-style-cast -Winit-self
-pedantic -Wreturn-type -Wunreachable-code -D REENTRANT -D_GNU_SOURCE test.c
-o test

> Implicit conversion are a nice thing to have ;-).
Yeah sure , but I prefer the secure way ;)


-----Message d'origine-----
De : gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] De la
part de Sven Eschenberg
Envoyé : jeudi 22 mai 2008 10:57
À : Laurent Dufréchou
Cc : gcc-help@gcc.gnu.org
Objet : Re: G++/GCC not detetcing stupid errors in code.

You are looking for -Wconversion I guess.

Implicit conversion are a nice thing to have ;-).

Regards

-Sven


Laurent Dufréchou schrieb:
> Hi there,
>
> I’m using g++ for the first time via gcc 4.1.2.
> I’ve written a little code (first C++ oriented and because guys with which
I
> work come from C, it is slightly modified to compile with G++ and gcc)
>
>   
>>>>>>>>>>>>>>>>>>>> Code >>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>                                         
>  
> //#include <iostream>
> #include <stdio.h>
>
> //using namespace std;
>
> int main()
>
> {
>
>                 int toto;
>
>                 short tata;
>
>                 toto = 1111118;
>
>                 tata = toto;  //error 1!
>
>                 //cout << toto << "tata:" << tata << endl;
>
>                 printf("%d %i",toto,tata);
>
>                 //return 0; //error 2 because no return
>
> }
>
>   
>
> I i compile with gcc (cc), it detects no int returned error (OK good
point)
> But the downcast (tata = toto) doesn’t raise any warning!
>
> If I use G++ the downcast is not detected and even more the return is not
> also detected (!)
>
> I was thining that Gcc was really strict and I choose it because I was
> thinking that, I’m quite disappointed :/
> I’ve tried –Wall –Wextra –pedantic + a ton of other switch with no luck…
>
> Do i miss something ? 
>
> How can I put Gcc in “user is stupid I need to check all” mode?
>
>
> Laurent
>
>   


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
       [not found]   ` <-457754682823264016@unknownmsgid>
@ 2008-05-22 11:55     ` Tom Browder
  2008-05-22 12:09       ` Laurent Dufréchou
  0 siblings, 1 reply; 10+ messages in thread
From: Tom Browder @ 2008-05-22 11:55 UTC (permalink / raw)
  To: Laurent Dufrechou; +Cc: Sven Eschenberg, Laurent Dufréchou, gcc-help

On Thu, May 22, 2008 at 4:00 AM, Laurent Dufrechou
<laurent.dufrechou@free.fr> wrote:
> Arf no... Here is my compile option :)
>
> g++ -march=nocona -Wall -Wfloat-equal -Wshadow -Wpointer-arith -Wcast-align
> -Wcast-qual -Wconversion -Wextra -Wreorder -Wold-style-cast -Winit-self

The failure to warn about the downcast may be a known problem.  I had
a problem the other way on a later version of gcc, and the gcc-dev
list has some threads about such.

I suggest checking bugzilla and also check at least gcc version 4.3.

-Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: G++/GCC not detetcing stupid errors in code.
  2008-05-22 11:55     ` Tom Browder
@ 2008-05-22 12:09       ` Laurent Dufréchou
  2008-05-22 12:23         ` Andrew Haley
                           ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Laurent Dufréchou @ 2008-05-22 12:09 UTC (permalink / raw)
  To: 'Tom Browder'
  Cc: 'Sven Eschenberg', 'Laurent Dufréchou', gcc-help

Yeah compiling with g++-4.3 solved the issue of downcasting. I've now a big
warning :) COOL!
Thanks Tom.
Any idea about the (not so worrying) no return in function requesting
return?
Gcc detect it but not g++. 
Perhaps I miss another keyword???

If you've got no idea, I will fill a bug report :)

Lauennt (code below)

//#include <iostream>
#include <stdio.h>

//using namespace std;

int main()

{

                int toto;

                short tata;

                toto = 1111118;

                tata = toto;  //error 1!

                //cout << toto << "tata:" << tata << endl;

                printf("%d %i",toto,tata);

                //return 0; //error 2 because no return <-----------------

}

-----Message d'origine-----
De : gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] De la
part de Tom Browder
Envoyé : jeudi 22 mai 2008 13:00
À : Laurent Dufrechou
Cc : Sven Eschenberg; Laurent Dufréchou; gcc-help@gcc.gnu.org
Objet : Re: G++/GCC not detetcing stupid errors in code.

On Thu, May 22, 2008 at 4:00 AM, Laurent Dufrechou
<laurent.dufrechou@free.fr> wrote:
> Arf no... Here is my compile option :)
>
> g++ -march=nocona -Wall -Wfloat-equal -Wshadow -Wpointer-arith
-Wcast-align
> -Wcast-qual -Wconversion -Wextra -Wreorder -Wold-style-cast -Winit-self

The failure to warn about the downcast may be a known problem.  I had
a problem the other way on a later version of gcc, and the gcc-dev
list has some threads about such.

I suggest checking bugzilla and also check at least gcc version 4.3.

-Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
  2008-05-22 12:09       ` Laurent Dufréchou
@ 2008-05-22 12:23         ` Andrew Haley
  2008-05-22 18:38           ` Laurent Dufréchou
  2008-05-22 12:24         ` Axel Freyn
  2008-05-23  2:16         ` Tom Browder
  2 siblings, 1 reply; 10+ messages in thread
From: Andrew Haley @ 2008-05-22 12:23 UTC (permalink / raw)
  To: Laurent Dufréchou
  Cc: 'Tom Browder', 'Sven Eschenberg', gcc-help

Laurent Dufréchou wrote:
> Yeah compiling with g++-4.3 solved the issue of downcasting. I've now a big
> warning :) COOL!
> Thanks Tom.
> Any idea about the (not so worrying) no return in function requesting
> return?
> Gcc detect it but not g++. 
> Perhaps I miss another keyword???
> 
> If you've got no idea, I will fill a bug report :)

No, it's your knowledge of C++.

ISO/IEC 14882:1998(E)
3.5 Program and linkage

"A return statement in main has the effect of leaving the main
function (destroying any objects with automatic storage duration) and
calling exit with the return value as the argument. If control reaches
the end of main without encountering a return statement, the effect is
that of executing

return 0;"

Note that this is a difference between C and C++: in C you must have
a return value.

Andrew.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
  2008-05-22 12:09       ` Laurent Dufréchou
  2008-05-22 12:23         ` Andrew Haley
@ 2008-05-22 12:24         ` Axel Freyn
  2008-06-09  0:44           ` Christopher Layne
  2008-05-23  2:16         ` Tom Browder
  2 siblings, 1 reply; 10+ messages in thread
From: Axel Freyn @ 2008-05-22 12:24 UTC (permalink / raw)
  To: gcc-help

Hello Laurent,

On Thu, May 22, 2008 at 01:54:14PM +0200, Laurent Dufréchou wrote:
> [...]
> Any idea about the (not so worrying) no return in function requesting
> return?
> Gcc detect it but not g++. 
> Perhaps I miss another keyword???
> 
> If you've got no idea, I will fill a bug report :)
> [...]
I would expect that this warning does not exist, because omitting the return-statement in
"main" is perfectly valid in C++: (C++-Standard, 3.6.1.3)
"If control reaches the end of main without encountering a return statement, the
effect is that of executing return 0;"

For other functions, g++ also emits a warning if you forget the return
statement.

Axel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: G++/GCC not detetcing stupid errors in code.
  2008-05-22 12:23         ` Andrew Haley
@ 2008-05-22 18:38           ` Laurent Dufréchou
  0 siblings, 0 replies; 10+ messages in thread
From: Laurent Dufréchou @ 2008-05-22 18:38 UTC (permalink / raw)
  To: 'Andrew Haley'
  Cc: 'Tom Browder', 'Sven Eschenberg', gcc-help

>No, it's your knowledge of C++, etc...
>Note that this is a difference between C and C++: in C you must have
>a return value.

Ok! Good, so there is no error in the code due to forced return 0 all is ok
now :)
Will read :
http://www.hep.wisc.edu/~pinghc/isocppstd/basic.html

Thx for the support,
Laurent

-----Message d'origine-----
De : Andrew Haley [mailto:aph@redhat.com] 
Envoyé : jeudi 22 mai 2008 14:09
À : Laurent Dufréchou
Cc : 'Tom Browder'; 'Sven Eschenberg'; gcc-help@gcc.gnu.org
Objet : Re: G++/GCC not detetcing stupid errors in code.

Laurent Dufréchou wrote:
> Yeah compiling with g++-4.3 solved the issue of downcasting. I've now a
big
> warning :) COOL!
> Thanks Tom.
> Any idea about the (not so worrying) no return in function requesting
> return?
> Gcc detect it but not g++. 
> Perhaps I miss another keyword???
> 
> If you've got no idea, I will fill a bug report :)

No, it's your knowledge of C++.

ISO/IEC 14882:1998(E)
3.5 Program and linkage

"A return statement in main has the effect of leaving the main
function (destroying any objects with automatic storage duration) and
calling exit with the return value as the argument. If control reaches
the end of main without encountering a return statement, the effect is
that of executing

return 0;"

Note that this is a difference between C and C++: in C you must have
a return value.

Andrew.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
  2008-05-22 12:09       ` Laurent Dufréchou
  2008-05-22 12:23         ` Andrew Haley
  2008-05-22 12:24         ` Axel Freyn
@ 2008-05-23  2:16         ` Tom Browder
  2 siblings, 0 replies; 10+ messages in thread
From: Tom Browder @ 2008-05-23  2:16 UTC (permalink / raw)
  To: Laurent Dufréchou; +Cc: Sven Eschenberg, gcc-help

On Thu, May 22, 2008 at 6:54 AM, Laurent Dufréchou
<laurent.dufrechou@gmail.com> wrote:
> Yeah compiling with g++-4.3 solved the issue of downcasting. I've now a big
> warning :) COOL!
> Thanks Tom.

You're welcome.  I suggest always staying with the latest releases of
gcc if you can.  It is always being improved and it forces users to
clean up their code and adhere to standards.

-Tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: G++/GCC not detetcing stupid errors in code.
  2008-05-22 12:24         ` Axel Freyn
@ 2008-06-09  0:44           ` Christopher Layne
  0 siblings, 0 replies; 10+ messages in thread
From: Christopher Layne @ 2008-06-09  0:44 UTC (permalink / raw)
  To: Axel Freyn; +Cc: gcc-help

On Thu, May 22, 2008 at 02:22:49PM +0200, Axel Freyn wrote:
> I would expect that this warning does not exist, because omitting the return-statement in
> "main" is perfectly valid in C++: (C++-Standard, 3.6.1.3)
> "If control reaches the end of main without encountering a return statement, the
> effect is that of executing return 0;"
> 
> For other functions, g++ also emits a warning if you forget the return
> statement.
> 
> Axel

This is something, that while valid by the C++ "Standard", I surely hope
doesn't become common practice.

-cl

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-06-09  0:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-22  8:56 G++/GCC not detetcing stupid errors in code Laurent Dufréchou
2008-05-22  9:00 ` Sven Eschenberg
2008-05-22 10:53   ` Laurent Dufrechou
     [not found]   ` <-457754682823264016@unknownmsgid>
2008-05-22 11:55     ` Tom Browder
2008-05-22 12:09       ` Laurent Dufréchou
2008-05-22 12:23         ` Andrew Haley
2008-05-22 18:38           ` Laurent Dufréchou
2008-05-22 12:24         ` Axel Freyn
2008-06-09  0:44           ` Christopher Layne
2008-05-23  2:16         ` Tom Browder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).