File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
2121 SourceLocation AmpLocation = Var.getLocation ();
2222 auto Token = utils::lexer::getPreviousToken (
2323 AmpLocation, Context.getSourceManager (), Context.getLangOpts ());
24+
25+ // For parameter packs the '&' must go before the '...' token
26+ if (Token.is (tok::ellipsis))
27+ return FixItHint::CreateInsertion (Token.getLocation (), " &" );
28+
2429 if (!Token.is (tok::unknown))
2530 AmpLocation = Lexer::getLocForEndOfToken (Token.getLocation (), 0 ,
2631 Context.getSourceManager (),
Original file line number Diff line number Diff line change @@ -384,7 +384,8 @@ Changes in existing checks
384384
385385- Improved :doc: `performance-unnecessary-value-param
386386 <clang-tidy/checks/performance/unnecessary-value-param>` by printing
387- the type of the diagnosed variable.
387+ the type of the diagnosed variable and correctly generating fix-it hints for
388+ parameter-pack arguments.
388389
389390- Improved :doc: `portability-template-virtual-member-function
390391 <clang-tidy/checks/portability/template-virtual-member-function>` check to
Original file line number Diff line number Diff line change @@ -96,3 +96,27 @@ void lambdaNonConstAutoValue() {
9696 };
9797 fn (ExpensiveToCopyType ());
9898}
99+
100+ template <typename ... Args>
101+ void ParameterPack (Args... args) {
102+ // CHECK-MESSAGES: [[@LINE-1]]:28: warning: the parameter 'args' of type 'ExpensiveToCopyType'
103+ // CHECK-FIXES: void ParameterPack(const Args&... args) {
104+ }
105+
106+ template <typename ... Args>
107+ void ParameterPackWithParams (const ExpensiveToCopyType E1 , ExpensiveToCopyType E2 , Args... args) {
108+ // CHECK-MESSAGES: [[@LINE-1]]:56: warning: the const qualified parameter 'E1'
109+ // CHECK-MESSAGES: [[@LINE-2]]:80: warning: the parameter 'E2'
110+ // CHECK-MESSAGES: [[@LINE-3]]:92: warning: the parameter 'args'
111+ // CHECK-FIXES: void ParameterPackWithParams(const ExpensiveToCopyType& E1, const ExpensiveToCopyType& E2, const Args&... args) {
112+ }
113+
114+ template <typename ... Args>
115+ void PackWithNonExpensive (int x, Args... args) {}
116+
117+ void instantiatedParameterPack () {
118+ ExpensiveToCopyType E;
119+ ParameterPack (E);
120+ ParameterPackWithParams (E, E, E);
121+ PackWithNonExpensive (5 , 5 );
122+ }
You can’t perform that action at this time.
0 commit comments