63 lines · cpp
1// RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-pro-bounds-pointer-arithmetic %t2 3// Fix PR36489 and detect auto-deduced value correctly.4typedef char* charPtr;5 6char *getPtr();7auto getPtrAuto() { return getPtr(); }8decltype(getPtr()) getPtrDeclType();9decltype(auto) getPtrDeclTypeAuto() { return getPtr(); }10auto getPtrWithTrailingReturnType() -> char *;11charPtr getCharPtr() { return getPtr(); }12 13void auto_deduction_binary() {14 auto p1 = getPtr() + 1;15 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: do not use pointer arithmetic16 auto p2 = getPtrAuto() + 1;17 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not use pointer arithmetic18 auto p3 = getPtrWithTrailingReturnType() + 1;19 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not use pointer arithmetic20 auto p4 = getPtr();21 auto *p5 = getPtr();22 p4 = p4 + 1;23 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic24 p5 = p5 + 1;25 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use pointer arithmetic26 auto p6 = getPtrDeclType() + 1;27 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: do not use pointer arithmetic28 auto p7 = getPtrDeclTypeAuto() + 1;29 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: do not use pointer arithmetic30 auto *p8 = getPtrDeclType() + 1;31 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not use pointer arithmetic32 auto *p9 = getPtrDeclTypeAuto() + 1;33 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: do not use pointer arithmetic34 auto p10 = getCharPtr() + 1;35 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use pointer 36 auto* p11 = getCharPtr() + 1;37 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use pointer arithmetic38}39 40void auto_deduction_subscript() {41 char p1 = getPtr()[2];42 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic43 auto p2 = getPtr()[3];44 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic45 46 char p3 = getPtrAuto()[4];47 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic48 auto p4 = getPtrAuto()[5];49 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic50 51 char p5 = getPtrWithTrailingReturnType()[6];52 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic53 auto p6 = getPtrWithTrailingReturnType()[7];54 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic55 56 auto p7 = getPtrDeclType()[8];57 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic58 auto p8 = getPtrDeclTypeAuto()[9];59 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic60 auto p9 = getCharPtr()[10];61 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use pointer arithmetic62}63