1 // RUN: %check_clang_tidy %s misc-misplaced-const %t -- -- -DUSING 2 // RUN: %check_clang_tidy %s misc-misplaced-const %t -- -- -DTYPEDEF 3 4 #ifdef TYPEDEF 5 typedef int int_; 6 typedef int *ptr_to_int; 7 typedef const int *ptr_to_const_int; 8 #endif 9 #ifdef USING 10 using int_ = int; 11 using ptr_to_int = int *; 12 using ptr_to_const_int = const int *; 13 #endif 14 const_pointers()15void const_pointers() { 16 if (const int *i = 0) { 17 i = 0; 18 // *i = 0; 19 } 20 21 if (const int_ *i = 0) { 22 i = 0; 23 // *i = 0; 24 } 25 26 if (const ptr_to_const_int i = 0) { 27 // i = 0; 28 // *i = 0; 29 } 30 31 // Potentially quite unexpectedly the int can be modified here 32 // CHECK-MESSAGES: :[[@LINE+1]]:24: warning: 'i' declared with a const-qualified {{.*}}; results in the type being 'int *const' instead of 'const int *' 33 if (const ptr_to_int i = 0) { 34 //i = 0; 35 36 *i = 0; 37 } 38 } 39 40 template <typename Ty> 41 struct S { 42 const Ty *i; 43 const Ty &i2; 44 }; 45 46 template struct S<int>; 47 template struct S<ptr_to_int>; // ok 48 template struct S<ptr_to_const_int>; 49 50 template <typename Ty> 51 struct U { 52 const Ty *i; 53 const Ty &i2; 54 }; 55 56 template struct U<int *>; // ok 57 58 struct T { 59 typedef void (T::*PMF)(); 60 fT61 void f() { 62 const PMF val = &T::f; // ok 63 } 64 }; 65