Aaron Ballman | cf6cefd | 2016-06-07 17:22:47 +0000 | [diff] [blame] | 1 | // RUN: %check_clang_tidy %s misc-misplaced-const %t |
| 2 | |
| 3 | typedef int plain_i; |
| 4 | typedef int *ip; |
| 5 | typedef const int *cip; |
| 6 | |
| 7 | void func() { |
| 8 | if (const int *i = 0) |
| 9 | ; |
| 10 | if (const plain_i *i = 0) |
| 11 | ; |
| 12 | if (const cip i = 0) |
| 13 | ; |
| 14 | |
| 15 | // CHECK-MESSAGES: :[[@LINE+1]]:16: warning: 'i' declared with a const-qualified typedef type; results in the type being 'int *const' instead of 'const int *' |
| 16 | if (const ip i = 0) |
| 17 | ; |
| 18 | } |
| 19 | |
| 20 | template <typename Ty> |
| 21 | struct S { |
| 22 | const Ty *i; |
| 23 | const Ty &i2; |
| 24 | }; |
| 25 | |
| 26 | template struct S<int>; |
| 27 | template struct S<ip>; // ok |
| 28 | template struct S<cip>; |
Aaron Ballman | 4c4bdba | 2016-06-07 17:32:07 +0000 | [diff] [blame] | 29 | |
| 30 | template <typename Ty> |
| 31 | struct U { |
| 32 | const Ty *i; |
| 33 | const Ty &i2; |
| 34 | }; |
| 35 | |
| 36 | template struct U<int *>; // ok |
Aaron Ballman | cf6cefd | 2016-06-07 17:22:47 +0000 | [diff] [blame] | 37 | |
| 38 | struct T { |
| 39 | typedef void (T::*PMF)(); |
| 40 | |
| 41 | void f() { |
| 42 | const PMF val = &T::f; // ok |
| 43 | } |
| 44 | }; |