Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -376,6 +376,8 @@ Improvements to Clang's diagnostics

- Clang now diagnoses when a ``requires`` expression has a local parameter of void type, aligning with the function parameter (#GH109831).

- Clang now emits a diagnostic note at the class declaration when the method definition does not match any declaration (#GH110638).

- Clang now omits warnings for extra parentheses in fold expressions with single expansion. (#GH101863)

Improvements to Clang's time-trace
Expand Down
12 changes: 8 additions & 4 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15566,6 +15566,14 @@ TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
return true;
}

// When there's only one expansion, the parentheses can be safely eliminated
// to avoid any extra redundancy that may result in incorrect checks
// For example, transforming (((args == 0) || ...)) into (args == 0)
// allows the omission of parentheses while ensuring precise representation
// and avoiding warnings regarding redundant parentheses.
if (*NumExpansions == 1)
Pattern = Pattern->IgnoreParens();

for (unsigned I = 0; I != *NumExpansions; ++I) {
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
getSema(), LeftFold ? I : *NumExpansions - I - 1);
Expand Down Expand Up @@ -15623,10 +15631,6 @@ TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
if (Result.isUnset())
return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
E->getOperator());

if (*NumExpansions == 1)
Result = Result.get()->IgnoreParens();

return Result;
}

Expand Down
41 changes: 20 additions & 21 deletions clang/test/SemaCXX/warn-assignment-condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,34 @@ void test() {
#undef EQ
}

void (*fn)();

void test2() {
if ((fn == test2)) {} // expected-warning {{equality comparison with extraneous parentheses}} \
// expected-note {{use '=' to turn this equality comparison into an assignment}} \
// expected-note {{remove extraneous parentheses around the comparison to silence this warning}}
if ((test2 == fn)) {}
namespace GH101863 {
void t1(auto... args) {
if (((args == 0) or ...)) { }
}

namespace rdar9027658 {
template <typename T>
void f(T t) {
if ((t.g == 3)) { } // expected-warning {{equality comparison with extraneous parentheses}} \
// expected-note {{use '=' to turn this equality comparison into an assignment}} \
// expected-note {{remove extraneous parentheses around the comparison to silence this warning}}
template <typename... Args>
void t2(Args... args) {
if (((args == 0) or ...)) { }
}

struct S { int g; };
void test() {
f(S()); // expected-note {{in instantiation}}
void t3(auto... args) {
if ((... && (args == 0))) { }
}

void t4(auto... a, auto... b) {
if (((a == 0) or ...) && ((b == 0) or ...)) { }
}

namespace GH101863 {
void foo(auto... args) {
if (((args == 0) or ...)) {} // ok
void t5(auto... args) {
if ((((args == 0) or ...))) { }
}

void bar() {
foo(3);
void test() {
t1(0, 1);
t2<>();
t3(1, 2, 3);
t3(0, 1);
t4(0, 1);
t5(0, 1);
}
}
Loading