Exemple #1
0
  E_func(e_char_signed_buf, E_tag);
  E_func(e_char_unsigned_buf, E_tag); // expected-warning {{argument type 'E_char_unsigned *' (aka 'unsigned char *') doesn't match specified 'e' type tag that requires 'E_char *' (aka 'char *')}}
#endif
}

// Tests for argument_with_type_tag.

#define F_DUPFD 10
#define F_SETLK 20

struct flock { };

static const int F_DUPFD_tag __attribute__(( type_tag_for_datatype(fcntl,int) )) = F_DUPFD;
static const int F_SETLK_tag __attribute__(( type_tag_for_datatype(fcntl,struct flock *) )) = F_SETLK;

int fcntl(int fd, int cmd, ...) __attribute__(( argument_with_type_tag(fcntl,3,2) ));

void test_argument_with_type_tag(struct flock *f)
{
  fcntl(0, F_DUPFD, 10); // no-warning
  fcntl(0, F_SETLK, f);  // no-warning

  fcntl(0, F_SETLK, 10); // expected-warning {{argument type 'int' doesn't match specified 'fcntl' type tag that requires 'struct flock *'}}
  fcntl(0, F_DUPFD, f);  // expected-warning {{argument type 'struct flock *' doesn't match specified 'fcntl' type tag that requires 'int'}}
}

void test_tag_expresssion(int b) {
  fcntl(0, b ? F_DUPFD : F_SETLK, 10); // no-warning
  fcntl(0, b + F_DUPFD, 10); // no-warning
  fcntl(0, (b, F_DUPFD), 10); // expected-warning {{expression result unused}}
}
// RUN: %clang_cc1 -fsyntax-only -verify %s

#define INT_TAG 42

static const int test_in
    __attribute__((type_tag_for_datatype(test, int))) = INT_TAG;

// Argument index: 1, Type tag index: 2
void test_bounds_index(...)
    __attribute__((argument_with_type_tag(test, 1, 2)));

// Argument index: 1, Type tag index: 2
void test_bounds_index_ptr(void *, ...)
    __attribute__((pointer_with_type_tag(test, 1, 2)));

// Argument index: 3, Type tag index: 1
void test_bounds_arg_index(...)
    __attribute__((argument_with_type_tag(test, 3, 1)));

class C {
public:
  // Argument index: 2, Type tag index: 3
  void test_bounds_index(...)
      __attribute__((argument_with_type_tag(test, 2, 3)));

  // Argument index: 2, Type tag index: 3
  void test_bounds_index_ptr(void *, ...)
      __attribute__((pointer_with_type_tag(test, 2, 3)));

  // Argument index: 4, Type tag index: 2
  void test_bounds_arg_index(...)