Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / testsuite / g++.dg / ext / va-arg-pack-len-2.C
blob0d369bdc9cb83f5e16325fce02384a19151b0340
1 // { dg-do compile }
2 // { dg-options "-O2" }
4 #include <stdarg.h>
6 extern int error_open_missing_mode (void)
7   __attribute__((__error__ ("open with O_CREAT needs 3 arguments, only 2 were given")));
8 extern int warn_open_too_many_arguments (void)
9   __attribute__((__warning__ ("open called with more than 3 arguments")));
11 extern int myopen2 (const char *path, int oflag);
12 extern int myopenva (const char *path, int oflag, ...);
14 extern inline __attribute__((always_inline, gnu_inline)) int
15 myopen (const char *path, int oflag, ...)
17   if (__builtin_va_arg_pack_len () > 1)
18     warn_open_too_many_arguments ();    // { dg-warning "called with more than 3" }
20   if (__builtin_constant_p (oflag))
21     {
22       if ((oflag & 0x40) != 0 && __builtin_va_arg_pack_len () < 1)
23         {
24           error_open_missing_mode ();   // { dg-error "needs 3 arguments, only 2 were given" }
25           return myopen2 (path, oflag);
26         }
27       return myopenva (path, oflag, __builtin_va_arg_pack ());
28     }
30   if (__builtin_va_arg_pack_len () < 1)
31     return myopen2 (path, oflag);
33   return myopenva (path, oflag, __builtin_va_arg_pack ());
36 int
37 main (void)
39   myopen ("h", 0x43);
40   myopen ("i", 0x43, 0644, 0655);
41   return 0;