46 lines · c
1// RUN: %check_clang_tidy %s misc-misplaced-const %t2 3typedef int plain_i;4typedef int *ip;5typedef const int *cip;6 7typedef void (*func_ptr)(void);8 9void func(void) {10 // ok11 const int *i0 = 0;12 const plain_i *i1 = 0;13 const cip i2 = 0; // const applies to both pointer and pointee.14 15 // Not ok16 const ip i3 = 0;17 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'i3' declared with a const-qualified typedef; results in the type being 'int *const' instead of 'const int *'18 19 ip const i4 = 0;20 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'i4' declared with a const-qualified typedef; results in the type being 'int *const' instead of 'const int *'21 22 const volatile ip i5 = 0;23 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'i5' declared with a const-qualified typedef; results in the type being 'int *const volatile' instead of 'const int *volatile'24}25 26void func2(const plain_i *i1,27 const cip i2,28 const ip i3,29 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'i3' declared with a const-qualified30 const int *i4) {31}32 33struct S {34 const int *i0;35 const plain_i *i1;36 const cip i2;37 const ip i3;38 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'i3' declared with a const-qualified39};40 41// Function pointers should not be diagnosed because a function42// pointer type can never be const.43void func3(const func_ptr fp) {44 const func_ptr fp2 = fp;45}46