This is the mail archive of the 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: Silently checking whether diagnostics would occur

On Wed, Sep 13, 2000 at 11:50:02AM -0400, Kaveh R. Ghazi wrote:
> Hi Gabriel,
> While writing a __builtin_printf expander, I found that it would be
> useful to be able to call the printf format checking routines silently
> from builtins.c to see if the printf call being expanded passed format
> checks before I try to optimize it.  (This needs to happen regardless
> of, and independent of, whether the user specifies -Wformat.)  The
> current format checking routines are setup to emit warnings at random
> points, not to return a handy status code.  (See check_format_info in
> c-common.c.)
> So rather than do a complete restructuring of the format checking
> function, I though it would be much easier and cleaner to be able to
> call the checks conceptually like this:
>  > check_diagnostics_silently = 1;  /* new global vars */
>  > diagnostic_occurred = 0;
>  > 
>  > <do something which might warn>
>  > 
>  > if (diagnostic_occurred) <react>
>  > check_diagnostics_silently = 0;
> and modify diagnostic.c:count_error to do this before anything else:
>  >   if (check_diagnostics_silently)
>  >     {
>  >       diagnostic_occurred = 1;
>  >       return 0;
>  >     }

I really, really do not like adding global variables for this purpose (yes, I'm
probably guily of just such behavior myself).  I would rather the checking be
abstracted into a function with an argument that says whether to issue the
warning or not, and a return value that indicates whether an error would have

Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:		phone: +1 978-486-9304
Non-work:	fax:   +1 978-692-4482

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