File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -157,9 +157,12 @@ void NonConstParameterCheck::diagnoseNonConstParameters() {
157157    if  (!Function)
158158      continue ;
159159    unsigned  Index = Par->getFunctionScopeIndex ();
160-     for  (FunctionDecl *FnDecl : Function->redecls ())
160+     for  (FunctionDecl *FnDecl : Function->redecls ()) {
161+       if  (FnDecl->getNumParams () <= Index)
162+         continue ;
161163      Fixes.push_back (FixItHint::CreateInsertion (
162164          FnDecl->getParamDecl (Index)->getBeginLoc (), " const " 
165+     }
163166
164167    diag (Par->getLocation (), " pointer parameter '%0' can be pointer to const" 
165168        << 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