summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/va-arg-pack-len-2.C
blob: 0d369bdc9cb83f5e16325fce02384a19151b0340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// { dg-do compile }
// { dg-options "-O2" }

#include <stdarg.h>

extern int error_open_missing_mode (void)
  __attribute__((__error__ ("open with O_CREAT needs 3 arguments, only 2 were given")));
extern int warn_open_too_many_arguments (void)
  __attribute__((__warning__ ("open called with more than 3 arguments")));

extern int myopen2 (const char *path, int oflag);
extern int myopenva (const char *path, int oflag, ...);

extern inline __attribute__((always_inline, gnu_inline)) int
myopen (const char *path, int oflag, ...)
{
  if (__builtin_va_arg_pack_len () > 1)
    warn_open_too_many_arguments ();	// { dg-warning "called with more than 3" }

  if (__builtin_constant_p (oflag))
    {
      if ((oflag & 0x40) != 0 && __builtin_va_arg_pack_len () < 1)
	{
	  error_open_missing_mode ();	// { dg-error "needs 3 arguments, only 2 were given" }
	  return myopen2 (path, oflag);
	}
      return myopenva (path, oflag, __builtin_va_arg_pack ());
    }

  if (__builtin_va_arg_pack_len () < 1)
    return myopen2 (path, oflag);

  return myopenva (path, oflag, __builtin_va_arg_pack ());
}

int
main (void)
{
  myopen ("h", 0x43);
  myopen ("i", 0x43, 0644, 0655);
  return 0;
}