help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug or a feature


From: Robert Heller
Subject: Re: bug or a feature
Date: Mon, 04 Jul 2005 20:26:41 +0200

  Anakreon <anakreonmejdi@yahoo.gr>,
  In a message on Mon, 04 Jul 2005 19:05:10 +0300, wrote :

A> I'm not sure this is a bug in g++ because is too obvious.
A> 
A> ===========code===========
A> class bug {
A> private:
A>    int mem;
A> public:
A>    void meth1();
A>    void meth2();
A> };
A> 
A> /*
A> g++ (GCC) 3.3.5 (Debian 1:3.3.5-13)
A> Copyright (C) 2003 Free Software Foundation, Inc.
A> This is free software; see the source for copying conditions.  There is NO
A> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
A> */
A> int main(int, char**) {
A>    //this should be an error
A>    bug bg;
A>    //if the line bellow is uncommented the linker catches the error
A>    //bg.meth1();
A>    return 1;
A> }
A> ===========code==============
A> 
A> When I compile this file no warnings are produced.
A> If I compile with the -Wall flag the only warning is:
A> gcc_bug.cpp: In function `int main(int, char**)':
A> gcc_bug.cpp:18: warning: unused variable `bug bg'
A> 
A> 
A> I think the compiler ought to stop the compilation with an error
A> since the 2 methods of the bug class are not implemented.
A> At least a warning should be produced.
A> 
A> If this is not a feature, I'll make  a proper bug submission

It is *never* an error to *declare* something you don't actually use, in
C or C++.  Dumb, but not an error.

If you don't use a method you declare you don't have to actually define
it either.

You can also declare variables you don't use either.  The compiler will
warn you about them though.  It will also warn you about staticly
declared functions you don't use either.

Anything in the *global* environment (eg. externals) are for the linker
to complain about (unresolved references).

A> 
A> 
A> Anakreon
A> 
A> 
A> 
A>                                                            

                                     \/
Robert Heller                        ||InterNet:   heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller  ||            heller@deepsoft.com
http://www.deepsoft.com              /\FidoNet:    1:321/153






     


reply via email to

[Prev in Thread] Current Thread [Next in Thread]