|
1 | | -// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-const-cast %t |
| 1 | +// RUN: %check_clang_tidy -check-suffix=STRICT %s cppcoreguidelines-pro-type-const-cast %t -- -config="{CheckOptions: {StrictMode: true}}" |
| 2 | +// RUN: %check_clang_tidy -check-suffix=NSTRICT %s cppcoreguidelines-pro-type-const-cast %t |
2 | 3 |
|
| 4 | +namespace Const { |
3 | 5 | const int *i; |
4 | 6 | int *j; |
5 | | -void f() { j = const_cast<int *>(i); } |
6 | | -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 7 | + |
| 8 | +void f() { |
| 9 | + j = const_cast<int *>(i); |
| 10 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:7: warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast] |
| 11 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 12 | + |
| 13 | + i = const_cast<const int*>(j); |
| 14 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 15 | + |
| 16 | + j = *const_cast<int **>(&i); |
| 17 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast] |
| 18 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 19 | + |
| 20 | + i = *const_cast<const int**>(&j); |
| 21 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 22 | + |
| 23 | + j = &const_cast<int&>(*i); |
| 24 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast] |
| 25 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 26 | + |
| 27 | + i = &const_cast<const int&>(*j); |
| 28 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 29 | +} |
| 30 | +} |
| 31 | + |
| 32 | +namespace Volatile { |
| 33 | +volatile int *i; |
| 34 | +int *j; |
| 35 | + |
| 36 | +void f() { |
| 37 | + j = const_cast<int *>(i); |
| 38 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:7: warning: do not use const_cast to remove volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 39 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 40 | + |
| 41 | + i = const_cast<volatile int*>(j); |
| 42 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 43 | + |
| 44 | + j = *const_cast<int **>(&i); |
| 45 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 46 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 47 | + |
| 48 | + i = *const_cast<volatile int**>(&j); |
| 49 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 50 | + |
| 51 | + j = &const_cast<int&>(*i); |
| 52 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 53 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 54 | + |
| 55 | + i = &const_cast<volatile int&>(*j); |
| 56 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 57 | +} |
| 58 | +} |
| 59 | + |
| 60 | +namespace ConstAndVolatile { |
| 61 | +const volatile int *i; |
| 62 | +int *j; |
| 63 | + |
| 64 | +void f() { |
| 65 | + j = const_cast<int *>(i); |
| 66 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:7: warning: do not use const_cast to remove const and volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 67 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 68 | + |
| 69 | + i = const_cast<const volatile int*>(j); |
| 70 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:7: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 71 | + |
| 72 | + j = *const_cast<int **>(&i); |
| 73 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove const and volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 74 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 75 | + |
| 76 | + i = *const_cast<const volatile int**>(&j); |
| 77 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 78 | + |
| 79 | + j = &const_cast<int&>(*i); |
| 80 | + // CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:8: warning: do not use const_cast to remove const and volatile qualifier [cppcoreguidelines-pro-type-const-cast] |
| 81 | + // CHECK-MESSAGES-STRICT: :[[@LINE-2]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 82 | + |
| 83 | + i = &const_cast<const volatile int&>(*j); |
| 84 | + // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:8: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] |
| 85 | +} |
| 86 | +} |
0 commit comments