File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -157,9 +157,12 @@ void NonConstParameterCheck::diagnoseNonConstParameters() {
157
157
if (!Function)
158
158
continue ;
159
159
unsigned Index = Par->getFunctionScopeIndex ();
160
- for (FunctionDecl *FnDecl : Function->redecls ())
160
+ for (FunctionDecl *FnDecl : Function->redecls ()) {
161
+ if (FnDecl->getNumParams () <= Index)
162
+ continue ;
161
163
Fixes.push_back (FixItHint::CreateInsertion (
162
164
FnDecl->getParamDecl (Index)->getBeginLoc (), " const " ));
165
+ }
163
166
164
167
diag (Par->getLocation (), " pointer parameter '%0' can be pointer to const" )
165
168
<< Par->getName () << Fixes;
Original file line number Diff line number Diff line change
1
+ // RUN: %check_clang_tidy %s readability-non-const-parameter %t
2
+
3
+ static int f ();
4
+
5
+ int f (p )
6
+ int * p ;
7
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: pointer parameter 'p' can be pointer to const [readability-non-const-parameter]
8
+ // CHECK-FIXES: {{^}} const int *p;{{$}}
9
+ {
10
+ return * p ;
11
+ }
You can’t perform that action at this time.
0 commit comments