44 lines · c
1// RUN: %check_clang_tidy %s misc-non-copyable-objects %t2 3typedef struct FILE {} FILE;4typedef struct pthread_cond_t {} pthread_cond_t;5typedef 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]8void 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 *'?10void 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 *'?12void i(pthread_cond_t c);13 14struct S {15 pthread_cond_t c; // ok16 // 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 20void 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; // match23 // 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 dereferenced25 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 dereferenced29 (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 dereferenced32 g(*f);33 34 pthread_mutex_t m; // ok35 h(m); // ok36 37 pthread_cond_t c; // ok38 i(c); // ok39 40 pthread_mutex_t *m1 = &m; // ok41 // 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 dereferenced42 h(*m1);43}44