public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Generating custom warning messages.
@ 1998-10-10 14:39 Ben Scherrey
  1998-10-11 22:21 ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Scherrey @ 1998-10-10 14:39 UTC (permalink / raw)
  To: egcs

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

	I've developed some class libraries for my client whose programmers are
dependent upon when writing their applications. One I am currently
working on is about to undergo some significant changes as I'm adding
exception handling to it. This will result in the programmers using some
alternative method calls (simple method overloading) but I will, for
now, keep supporting the old calls as well so as not to break any of the
existing application code.

	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. This would allow all existing code to
build/run but also make it easier for those who want to update their old
code to find where they need to make changes.

	Is such a thing possible? I've seen compilers that support #pragma
error <msg> but not warnings. Also, can the warning be generated only
when a call actually resolves to the deprecated method? Certainly this
would be an extremely useful feature for developers but can it be
implemented?

	Appreciate any ideas in this matter,

		Ben Scherrey

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

* Re: Generating custom warning messages.
  1998-10-10 14:39 Generating custom warning messages Ben Scherrey
@ 1998-10-11 22:21 ` Alexandre Oliva
  1998-10-12  8:04   ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 1998-10-11 22:21 UTC (permalink / raw)
  To: scherrey; +Cc: egcs

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

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

* Re: Generating custom warning messages.
  1998-10-11 22:21 ` Alexandre Oliva
@ 1998-10-12  8:04   ` Andreas Schwab
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 1998-10-12  8:04 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: scherrey, egcs

Alexandre Oliva <oliva@dcc.unicamp.br> writes:

|> Ben Scherrey <scherrey@gte.net> writes:
|> 
|> > 	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.

That is already implemented in GNU ld, using the so called "warning
symbols".  See the GNU libc for an application.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

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

end of thread, other threads:[~1998-10-12  8:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-10 14:39 Generating custom warning messages Ben Scherrey
1998-10-11 22:21 ` Alexandre Oliva
1998-10-12  8:04   ` Andreas Schwab

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