This is the mail archive of the gcc@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]

Re: Generating custom warning messages.


Ben Scherrey <scherrey@gte.net> writes:

> (Thanx to all who helped me get my PDBUG back and running for egcs...)

Sure.  BTW, I've just thought that

#define PDBUG if(0) cout

is a bit unsafe if used in this case:

     if (condition)
	PDBUG << "condition is true";
     else
	do_something_important();

Since else matches the closest if, it will match the if(0) in PDBUG,
not the one you intended it to match.

In order to make it safe, define it as:

#define PDBUG if(true) {} else cout

> 	What I would like to be able to do is generate a warning message during
> compile/link time whenever a deprecated method is called and have it
> suggest use of the new one.

The easiest way to accomplish that would be to define a new
__attribute__ to g++, such as __attribute__((deprecated)), and arrange 
that it prints a warning message when the method is called.  I don't
know how easy it would be to implement it, though.

I've tried real hard to find a solution using an additional argument
with a default value that would cause the instantiation of a template
that would contain code that would cause a warning message to be
issued.  Unfortunately, the default argument causes the template to be
instantiated too early, and the warning ends up being always printed,
which is not useful :-(

Can anyone think of another solution?

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


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