| 1 |
// RUN: %check_clang_tidy %s misc-non-copyable-objects %t |
| 2 |
|
| 3 |
typedef struct FILE {} FILE; |
| 4 |
typedef struct pthread_cond_t {} pthread_cond_t; |
| 5 |
typedef int pthread_mutex_t; |
| 6 |
|
| 7 |
// CHECK-MESSAGES: :[[@LINE+1]]:13: warning: 'f' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'? [misc-non-copyable-objects] |
| 8 |
void g(FILE f); |
| 9 |
// CHECK-MESSAGES: :[[@LINE+1]]:24: warning: 'm' declared as type 'pthread_mutex_t', which is unsafe to copy; did you mean 'pthread_mutex_t *'? |
| 10 |
void h(pthread_mutex_t m); |
| 11 |
// CHECK-MESSAGES: :[[@LINE+1]]:23: warning: 'c' declared as type 'pthread_cond_t', which is unsafe to copy; did you mean 'pthread_cond_t *'? |
| 12 |
void i(pthread_cond_t c); |
| 13 |
|
| 14 |
struct S { |
| 15 |
pthread_cond_t c; // ok |
| 16 |
// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: 'f' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'? |
| 17 |
FILE f; |
| 18 |
}; |
| 19 |
|
| 20 |
void func(FILE *f) { |
| 21 |
// CHECK-MESSAGES: :[[@LINE+1]]:8: warning: 'f1' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'? |
| 22 |
FILE f1; // match |
| 23 |
// CHECK-MESSAGES: :[[@LINE+2]]:8: warning: 'f2' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'? |
| 24 |
// CHECK-MESSAGES: :[[@LINE+1]]:13: warning: expression has opaque data structure type 'FILE'; type should only be used as a pointer and not dereferenced |
| 25 |
FILE f2 = *f; |
| 26 |
// CHECK-MESSAGES: :[[@LINE+1]]:15: warning: 'f3' declared as type 'FILE', which is unsafe to copy; did you mean 'FILE *'? |
| 27 |
struct FILE f3; |
| 28 |
// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: expression has opaque data structure type 'FILE'; type should only be used as a pointer and not dereferenced |
| 29 |
(void)sizeof(*f); |
| 30 |
(void)sizeof(FILE); |
| 31 |
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: expression has opaque data structure type 'FILE'; type should only be used as a pointer and not dereferenced |
| 32 |
g(*f); |
| 33 |
|
| 34 |
pthread_mutex_t m; // ok |
| 35 |
h(m); // ok |
| 36 |
|
| 37 |
pthread_cond_t c; // ok |
| 38 |
i(c); // ok |
| 39 |
|
| 40 |
pthread_mutex_t *m1 = &m; // ok |
| 41 |
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: expression has opaque data structure type 'pthread_mutex_t'; type should only be used as a pointer and not dereferenced |
| 42 |
h(*m1); |
| 43 |
} |