Skip to content
Merged
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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Improvements to Clang's diagnostics
Moved the warning for a missing (though implied) attribute on a redeclaration into this group.
Added a new warning in this group for the case where the attribute is missing/implicit on
an override of a virtual method.
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
parenthesis when diagnosing malformed fold expressions. (#GH151787)

Improvements to Clang's time-trace
----------------------------------
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaTemplateVariadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,8 @@ static void CheckFoldOperand(Sema &S, Expr *E) {
S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
<< E->getSourceRange()
<< FixItHint::CreateInsertion(E->getBeginLoc(), "(")
<< FixItHint::CreateInsertion(E->getEndLoc(), ")");
<< FixItHint::CreateInsertion(S.getLocForEndOfToken(E->getEndLoc()),
")");
}
}

Expand Down
29 changes: 29 additions & 0 deletions clang/test/FixIt/fixit-c++17.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clang_cc1 -verify -std=c++17 -pedantic-errors %s
// RUN: cp %s %t
// RUN: not %clang_cc1 -x c++ -std=c++17 -fixit %t
// RUN: %clang_cc1 -Wall -pedantic-errors -x c++ -std=c++17 %t

/* This is a test of the various code modification hints that only
apply in C++17. */
template<int... args>
int foo() {
int a = (args + 1 + ...); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:22-[[@LINE-2]]:22}:")"
int b = (args + 123 + ...); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:24-[[@LINE-2]]:24}:")"
int c = (args + 1 + 2 + ...); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:26-[[@LINE-2]]:26}:")"
int e = (... + 1 + args); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:20-[[@LINE-1]]:20}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:28-[[@LINE-2]]:28}:")"
int f = (1 + ... + args + 1); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:32-[[@LINE-2]]:32}:")"
int g = (args + 1 + ... + 1); // expected-error {{expression not permitted as operand of fold expression}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"("
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:22-[[@LINE-2]]:22}:")"
return a + b + c + e + f + g;
}