[clang][c++20] Fix false warning for unused private fields when a class has only...
authorAlexandru Octavian Butiu <alexandru.octavian.butiu@gmail.com>
Tue, 22 Jun 2021 16:33:30 +0000 (18:33 +0200)
committerHans Wennborg <hans@chromium.org>
Tue, 22 Jun 2021 16:40:16 +0000 (18:40 +0200)
commit78d404a11dd33c8349fd9b6ef5876d523c457f0e
treebaacc2538e927705af5503e2026c9841ae74a00a
parent002905907432b19c1ce303d2cd8e3896dd360683
[clang][c++20] Fix false warning for unused private fields when a class has only defaulted comparison operators.

Fixes bug 50263

When "unused-private-field" flag is on if you have a struct with private
members and only defaulted comparison operators clang will warn about
unused private fields.

If you where to write the comparison operators by hand no warning is
produced.

This is a bug since defaulting a comparison operator uses all private
members .

The fix is simple, in CheckExplicitlyDefaultedFunction just clear the
list of unused private fields if the defaulted function is a comparison
function.

Differential revision: https://reviews.llvm.org/D102186
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-unused-private-field.cpp