Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ FixItHint changeVarDeclToReference(const VarDecl &Var, ASTContext &Context) {
SourceLocation AmpLocation = Var.getLocation();
auto Token = utils::lexer::getPreviousToken(
AmpLocation, Context.getSourceManager(), Context.getLangOpts());

// For parameter packs the '&' must go before the '...' token
if (Token.is(tok::ellipsis))
return FixItHint::CreateInsertion(Token.getLocation(), "&");

if (!Token.is(tok::unknown))
AmpLocation = Lexer::getLocForEndOfToken(Token.getLocation(), 0,
Context.getSourceManager(),
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ Changes in existing checks

- Improved :doc:`performance-unnecessary-value-param
<clang-tidy/checks/performance/unnecessary-value-param>` by printing
the type of the diagnosed variable.
the type of the diagnosed variable and correctly generating fix-it hints for
parameter-pack arguments.

- Improved :doc:`portability-template-virtual-member-function
<clang-tidy/checks/portability/template-virtual-member-function>` check to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,34 @@ void lambdaNonConstAutoValue() {
};
fn(ExpensiveToCopyType());
}

template <typename... Args>
void ParameterPack(Args... args) {
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: the parameter 'args' of type 'ExpensiveToCopyType'
// CHECK-FIXES: void ParameterPack(const Args&... args) {
}

template <typename... Args>
void ParameterPackConst(Args const... args) {
// CHECK-MESSAGES: [[@LINE-1]]:39: warning: the const qualified parameter 'args' of type 'const ExpensiveToCopyType'
// CHECK-FIXES: void ParameterPackConst(Args const&... args) {
}

template <typename... Args>
void ParameterPackWithParams(const ExpensiveToCopyType E1, ExpensiveToCopyType E2, Args... args) {
// CHECK-MESSAGES: [[@LINE-1]]:56: warning: the const qualified parameter 'E1'
// CHECK-MESSAGES: [[@LINE-2]]:80: warning: the parameter 'E2'
// CHECK-MESSAGES: [[@LINE-3]]:92: warning: the parameter 'args'
// CHECK-FIXES: void ParameterPackWithParams(const ExpensiveToCopyType& E1, const ExpensiveToCopyType& E2, const Args&... args) {
}

template <typename... Args>
void PackWithNonExpensive(int x, Args... args) {}

void instantiatedParameterPack() {
ExpensiveToCopyType E;
ParameterPack(E);
ParameterPackConst(E);
ParameterPackWithParams(E, E, E);
PackWithNonExpensive(5, 5);
}