Re: Let gcc generate a warning or an error?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 25 Dec 2008, Georg-Johann Lay wrote:

       __builtin_error ("foo must be used with a compile time constant");

Is there a way to generate an error/warning/info by making gcc
call error/warning/info?

The following is an example taken randomly from glibc, it should be enough to get the idea (may require gcc-4.3+):

sys/cdefs.h:
# define __warndecl(name, msg) \
  extern void name (void) __attribute__((__warning__ (msg)))
# define __warnattr(msg) __attribute__((__warning__ (msg)))
# define __errordecl(name, msg) \
  extern void name (void) __attribute__((__error__ (msg)))

bits/fcntl2.h:
__errordecl (__open_too_many_args,
             "open can be called either with 2 or 3 arguments, not more");
__errordecl (__open_missing_mode,
             "open with O_CREAT in second argument needs 3 arguments");

__extern_always_inline int
open (__const char *__path, int __oflag, ...)
{
  if (__va_arg_pack_len () > 1)
    __open_too_many_args ();

  if (__builtin_constant_p (__oflag))
    {
      if ((__oflag & O_CREAT) != 0 && __va_arg_pack_len () < 1)
        {
          __open_missing_mode ();
          return __open_2 (__path, __oflag);
        }
      return __open_alias (__path, __oflag, __va_arg_pack ());
    }

  if (__va_arg_pack_len () < 1)
    return __open_2 (__path, __oflag);

  return __open_alias (__path, __oflag, __va_arg_pack ());
}


--
Marc Glisse

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux