llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

readability-avoid-const-params-in-decls removes const from template parameter

Open gfrontera opened this issue 8 years ago • 4 comments

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.

gfrontera avatar Jul 03 '18 12:07 gfrontera

mentioned in issue llvm/llvm-bugzilla-archive#49063

adesitter avatar Nov 27 '21 04:11 adesitter

*** Bug llvm/llvm-bugzilla-archive#49063 has been marked as a duplicate of this bug. ***

llvmbot avatar Feb 08 '21 01:02 llvmbot

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.

tonyelewis avatar Oct 09 '18 19:10 tonyelewis

Fixed by commit a34532c330f61c35612bb0c4b753979307020608.

ymand avatar Jun 15 '22 17:06 ymand