| 1 |
// RUN: %check_clang_tidy %s readability-avoid-return-with-void-value %t |
| 2 |
// RUN: %check_clang_tidy -check-suffixes=,INCLUDE-MACROS %s readability-avoid-return-with-void-value %t \ |
| 3 |
// RUN: -- -config="{CheckOptions: [{key: readability-avoid-return-with-void-value.IgnoreMacros, value: false}]}" \ |
| 4 |
// RUN: -- |
| 5 |
// RUN: %check_clang_tidy -check-suffixes=LENIENT %s readability-avoid-return-with-void-value %t \ |
| 6 |
// RUN: -- -config="{CheckOptions: [{key: readability-avoid-return-with-void-value.StrictMode, value: false}]}" \ |
| 7 |
// RUN: -- |
| 8 |
|
| 9 |
void f1(); |
| 10 |
|
| 11 |
void f2() { |
| 12 |
return f1(); |
| 13 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 14 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 15 |
// CHECK-FIXES: f1(); |
| 16 |
} |
| 17 |
|
| 18 |
void f3(bool b) { |
| 19 |
if (b) return f1(); |
| 20 |
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 21 |
// CHECK-FIXES: if (b) { f1(); return; |
| 22 |
// CHECK-NEXT: } |
| 23 |
return f2(); |
| 24 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 25 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 26 |
// CHECK-FIXES: f2(); |
| 27 |
// CHECK-FIXES-LENIENT: f2(); |
| 28 |
} |
| 29 |
|
| 30 |
template<class T> |
| 31 |
T f4() {} |
| 32 |
|
| 33 |
void f5() { |
| 34 |
{ return f4<void>(); } |
| 35 |
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 36 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:7: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 37 |
// CHECK-FIXES: { f4<void>(); return; } |
| 38 |
// CHECK-FIXES-LENIENT: { f4<void>(); return; } |
| 39 |
} |
| 40 |
|
| 41 |
void f6() { return; } |
| 42 |
|
| 43 |
int f7() { return 1; } |
| 44 |
|
| 45 |
int f8() { return f7(); } |
| 46 |
|
| 47 |
void f9() { |
| 48 |
return (void)f7(); |
| 49 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 50 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 51 |
// CHECK-FIXES: (void)f7(); |
| 52 |
// CHECK-FIXES-LENIENT: (void)f7(); |
| 53 |
} |
| 54 |
|
| 55 |
#define RETURN_VOID return (void)1 |
| 56 |
|
| 57 |
void f10() { |
| 58 |
RETURN_VOID; |
| 59 |
// CHECK-MESSAGES-INCLUDE-MACROS: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 60 |
} |
| 61 |
|
| 62 |
template <typename A> |
| 63 |
struct C { |
| 64 |
C(A) {} |
| 65 |
}; |
| 66 |
|
| 67 |
template <class T> |
| 68 |
C<T> f11() { return {}; } |
| 69 |
|
| 70 |
using VOID = void; |
| 71 |
|
| 72 |
VOID f12(); |
| 73 |
|
| 74 |
VOID f13() { |
| 75 |
return f12(); |
| 76 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 77 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 78 |
// CHECK-FIXES: f12(); return; |
| 79 |
// CHECK-FIXES-LENIENT: f12(); return; |
| 80 |
(void)1; |
| 81 |
} |
| 82 |
|
| 83 |
void f14() { |
| 84 |
return /* comment */ f1() /* comment */ ; |
| 85 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 86 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 87 |
// CHECK-FIXES: /* comment */ f1() /* comment */ ; return; |
| 88 |
// CHECK-FIXES-LENIENT: /* comment */ f1() /* comment */ ; return; |
| 89 |
(void)1; |
| 90 |
} |
| 91 |
|
| 92 |
void f15() { |
| 93 |
return/*comment*/f1()/*comment*/;//comment |
| 94 |
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 95 |
// CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 96 |
// CHECK-FIXES: /*comment*/f1()/*comment*/; return;//comment |
| 97 |
// CHECK-FIXES-LENIENT: /*comment*/f1()/*comment*/; return;//comment |
| 98 |
(void)1; |
| 99 |
} |
| 100 |
|
| 101 |
void f16(bool b) { |
| 102 |
if (b) return f1(); |
| 103 |
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 104 |
// CHECK-FIXES: if (b) { f1(); return; |
| 105 |
// CHECK-NEXT: } |
| 106 |
else return f2(); |
| 107 |
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value] |
| 108 |
// CHECK-FIXES: else { f2(); return; |
| 109 |
// CHECK-NEXT: } |
| 110 |
} |