This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

trying to use warnings effectivly


   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'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]