public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* trying to use warnings effectivly
@ 2002-02-20  5:35 Edmund Green
  0 siblings, 0 replies; only message in thread
From: Edmund Green @ 2002-02-20  5:35 UTC (permalink / raw)
  To: gcc-help

   I'm using gcc 2.96, and have read (and re-read) the info files so fear that I already know the answer to this 
question, but hopefully I'm wrong:

   Is there any way to selectivly disable or enable warnings for just parts of my C++ source/header files, or not give 
warnings for system includes? I would like to use the -Werror option on my code, but without this facility I am unable 
to do this without disabling a lot of warnings that I would like to keep enabled for the bulk of my code.

   There are actually two slightly different cases here.

1) System headers:
   I'm using a standard RedHat7.1 installation, on which many of the STL headers will give warnings regarding shadowed 
variables and signed/unsigned comparisons, which I would still like to be warned about in my own code (and also 
non-inlinable methods, but I can live without that warning enabled)
   If the compiler cannot do it then I suppose that I could process the output to strip warning lines generated by files 
in the system include directories, but it not quite as simple as just piping the output through grep because it is 
multi-line warnings like the following which I want to ignore:

In file included from /usr/include/g++-3/string:6,
                  from common/Defines.hpp:13,
                  from common/anotherFile.hpp:8,
                  from someSourceFile.cpp:12:
/usr/include/g++-3/std/bastring.h: In method `basic_string<charT,
traits, Allocator> &basic_string<charT, traits, Allocator>::replace
(charT *, charT *, InputIterator, InputIterator)':
/usr/include/g++-3/std/bastring.h:440: warning: declaration of `j1' shadows global declaration


2) Unused parameters:
   It would seem good practice to use the -Wunused-parameter most of the time, but it is often the case in callbacks and 
sometimes in virtual methods that there are going to be unused parameters. My understanding of the documentation is that 
I should be able to use the unused attribute to mark parameters which I know are not being used, but I have been unable 
to get this to work succesfully.

   can anybody show me where I'm going wrong on this example:

   // file Sample.cpp
   struct SomeObject;
   void myFunction(const SomeObject* __attribute__ ((unused)) anUnusedArg)
   {
     // dummy callback that doesn't use the argument
   }

then compile with
$ gcc -Wunused-parameter -c -o sample.o sample.cpp
sample.cpp: In function `void myFunction (const SomeObject *)':
sample.cpp:4: warning: unused parameter `const SomeObject *anUnusedArg'

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-02-20 12:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-20  5:35 trying to use warnings effectivly Edmund Green

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).