46 lines · cpp
1// RUN: %check_clang_tidy %s readability-redundant-function-ptr-dereference %t2 3void f(int i);4 5void positive() {6 void (*p)(int) = f;7 8 (**p)(1);9 // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated dereference of function pointer [readability-redundant-function-ptr-dereference]10 // CHECK-FIXES: (*p)(1);11 (*****p)(2);12 // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated13 // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: redundant repeated14 // CHECK-MESSAGES: :[[@LINE-3]]:6: warning: redundant repeated15 // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: redundant repeated16 // CHECK-FIXES: (*p)(2);17}18 19template<typename T>20void invoke(const T& fn) {21 fn(0); // 122 (*fn)(0); // 223 // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: redundant repeated24 // CHECK-FIXES: fn(0); // 125 // CHECK-FIXES: (fn)(0); // 226 // FIXME: Remove unnecessary parentheses.27}28 29void f1(int);30void f2(double);31void f3(char);32 33void instantiate() {34 invoke(f1);35 invoke(f2);36 invoke(f3);37 invoke([](unsigned) {});38}39 40void negative() {41 void (*q)(int) = &f;42 43 q(1);44 (*q)(2);45}46