readability-avoid-const-params-in-decls removes const from template parameter
| Bugzilla Link | 38035 |
| Version | unspecified |
| OS | Linux |
| Attachments | Minimum working example |
| CC | @adesitter,@EugeneZelenko,@tonyelewis |
Extended Description
The suggested fix for the attached minimum working example does not compile, as it removes the wrong 'const' from the function declaration.
$ clang-tidy -checks='-,readability-avoid-const-params' mwe.cpp -fix 4 warnings generated. main.cpp:3:10: warning: parameter 1 is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls] void foo(const std::list<const int *>); ^ ~~~~~~~~~ main.cpp:3:26: note: FIX-IT applied suggested code changes void foo(const std::list<const int *>); ^ clang-tidy applied 1 of 1 suggested fixes.
mentioned in issue llvm/llvm-bugzilla-archive#49063
*** Bug llvm/llvm-bugzilla-archive#49063 has been marked as a duplicate of this bug. ***
Another example without any #includes :
template <typename...> struct x {}; namespace a { void f(const x<const int &>); } void a::f(const x<const int &>) {}
Running clang-tidy -fix -checks=readability-avoid-const-params-in-decls on this modifies such that it no longer compiles with clang++ -fsyntax-only.
Fixed by commit a34532c330f61c35612bb0c4b753979307020608.