Page MenuHomePhabricator

[libc++] Enable modernize-use-equals-delete
Needs RevisionPublic

Authored by philnik on Mar 8 2022, 6:58 AM.

Details

Reviewers
ldionne
Quuxplusone
Mordante
Group Reviewers
Restricted Project

Diff Detail

Unit TestsFailed

TimeTest
4,220 mslibcxx CI C++03 > llvm-libc++-shared-cfg-in.libcxx::clang_tidy.sh.cpp
Script: -- : 'RUN: at line 11'; clang-tidy /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/libcxx/test/libcxx/clang_tidy.sh.cpp --warnings-as-errors=* -header-filter=.* -- -Wno-unknown-warning-option -nostdinc++ -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/build/generic-cxx03/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/build/generic-cxx03/include/c++/v1 -I /home/libcxx-builder/.buildkite-agent/builds/dc323b72550c-1/llvm-project/libcxx-ci/libcxx/test/support -std=c++03 -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER

Event Timeline

philnik created this revision.Mar 8 2022, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2022, 6:58 AM
philnik requested review of this revision.Mar 8 2022, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2022, 6:58 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Mordante accepted this revision as: Mordante.Mar 8 2022, 11:07 AM
Mordante added a subscriber: Mordante.

Thanks for working on these cleanups! In general LGTM when the CI passes.

libcxx/include/future
1628

As a note for other followup patches. I prefer these clang-tidy improvements not to do other cleanups in the same patch. I would prefer to see that in different patches. This makes reviewing them easier.

libcxx/include/__functional/function.h
264

FWIW, my personal style on the OOP polymorphic types like __base (where they are clearly just abstract base classes with lots of pure virtual methods) is not to bother with the special member functions at all. Nobody's seriously going to be value-semantic-copying this type, so why waste the two LoC preventing it?
But I see the "guardrail against accidental copying" argument, so I'm not asking to change this (unless my comment happens to start a new consensus :)).

libcxx/include/__functional/reference_wrapper.h
37–38

Eliminate the NOLINT comment and just make these two declarations public; it can't hurt.
(I agree that 54276 is a real bug, though.)

Ditto in ref_view below.

libcxx/include/iosfwd
287

Stylistically, I'd prefer to see these placed between new lines 278 and 279, so it goes "ctors, assignment operators, dtors." Ditto throughout (at least in the cases where you're already shuffling code around).

libcxx/include/tuple
363–365

Consider west-consting line 363 at the same time, and also doing something explicitly about __tuple_leaf& operator=(__tuple_leaf&&). I actually don't know off the top of my head what happens to it right now.

EricWF added a subscriber: EricWF.Mar 8 2022, 5:16 PM

Are we sure this doesn't break the ABI because changing user declared constructors into delete constructors can do that, Can't it?

Are we sure this doesn't break the ABI because changing user declared constructors into delete constructors can do that, Can't it?

How could it change the ABI? The functions can never be called, and it doesn't change any type traits AFAIK. It's not like with = default that the type could be trivially_something after the change that it wasn't before.

EricWF added a comment.Mar 8 2022, 6:11 PM

Are we sure this doesn't break the ABI because changing user declared constructors into delete constructors can do that, Can't it?

How could it change the ABI? The functions can never be called, and it doesn't change any type traits AFAIK. It's not like with = default that the type could be trivially_something after the change that it wasn't before.

From the Itanium C++ ABI Specification:

non-trivial for the purposes of calls

A type is considered non-trivial for the purposes of calls if:

  • it has a non-trivial copy constructor, move constructor, or destructor, or
  • all of its copy and move constructors are deleted.

This definition, as applied to class types, is intended to be the complement of the definition in [class.temporary]p3 of types for which an extra temporary is allowed when passing or returning a type. A type which is trivial for the purposes of the ABI will be passed and returned according to the rules of the base C ABI, e.g. in registers; often this has the effect of performing a > trivial copy of the type.

@EricWF And in what scenario would that change the ABI? If there are no copy- or move-constructors, then all are deleted by definition, and if there is one it isn't trivial.

@EricWF And in what scenario would that change the ABI? If there are no copy- or move-constructors, then all are deleted by definition, and if there is one it isn't trivial.

@philnik: Eric is at least partly correct (and your original goalpost was wrong): this transformation can definitely change the is_trivially_fooable properties of the type. However, I haven't yet been able to get this to cause an actual calling-convention difference. https://godbolt.org/z/d17PM8dWc It seems to me that the wording Eric quoted was probably designed precisely to prevent the breakage Eric is concerned about! It basically says, "Deleted SMFs don't affect triviality, unless you're using deleted SMFs to replicate the old C++98 trick of declare-but-not-defining all your SMFs. If all your SMFs are deleted, then we'll assume you still want to be non-trivial for the purposes of calls."
So I believe Eric is correct about the possibility of breakage here, and I think you should go look at the triviality-for-purposes-of-calls of all of the affected classes (i.e., don't just trust clang-tidy's mechanical change; go through it line by line). I predict you'll find that every affected class is either still non-trivial for other reasons (e.g. virtual dtor), or is a detail type like __save_flags where we don't care about its triviality. But yeah, Eric's convinced me that we shouldn't just assume this is safe.

The important bit is this (emphasis mine):

A type is considered non-trivial for the purposes of calls if:

  • it has a non-trivial copy constructor, move constructor, or destructor, or
  • all of its copy and move constructors are deleted.

I went through all the changes in this patch, and I think the key question we need an answer to is:

When a copy assignment operator or copy constructor is explicitly deleted, there is no implicit move constructor generated by the compiler. But does the compiler not declare any move constructor, or does it declare one and mark it as deleted? I wasn't able to find out by reading http://eel.is/c++draft/class.copy.ctor, but it may be easy to answer for others here.

This is relevant because some classes go from having a user-declared private operator=(T const&) to having a deleted one. I believe it's possible for such a type to be trivial for the purpose of calls. However, if we change it to operator(T const&) = delete and the compiler then implicitly declares T(T const&) = delete, we'd go from trivial to non-trivial.

Anyway, I've left some not-done comments on the ones where I'm not 100% confident that this patch isn't changing behavior. I suspect it is correct, I just need to understand why.

Note: In my review, TFPC stands for "Trivial For the Purpose of Call"

libcxx/include/__bit_reference
159

I'm not sure about this one, see question.

libcxx/include/__functional/function.h
262

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/__locale
61

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/__split_buffer
76

Code was not TFPC, and isn't after patch because we have a move ctor but it is user-defined.

libcxx/include/deque
1042

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/forward_list
516

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/future
1623

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/iosfwd
286

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/list
527

Can we move these down near the other constructors?

529

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/locale
3652

Code was not TFPC before, and it's not after because there's a user-defined destructor.

3924

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/map
692

I'm not sure about this one. I think it was TFPC before the patch, because there were no copy/move ctors declared.

After the patch, there shouldn't be any copy/move ctor declared unless the compiler declares them as deleted, in which case it would become non-TFPC.

libcxx/include/regex
1433

Code was not TFPC before, and it's not after because there's a user-defined destructor.

2210

I'm not sure about this one, see question.

2251

I'm not sure about this one, see question.

2293

I'm not sure about this one, see question.

2349

I'm not sure about this one, see question.

3147

I'm not sure about this one, see question.

libcxx/include/thread
153

Code was not TFPC before, and it's not after because there's a user-defined destructor.

libcxx/include/tuple
301

This one has defaulted copy and move constructors, so this won't change triviality.

363

This one has defaulted copy and move constructors, so this won't change triviality.

libcxx/include/unordered_map
780

This one is not TFPC before and not TFPC after because it has user-defined copy/move ctors.

libcxx/include/vector
787

Code was not TFPC before, and it's not after because there's a user-defined destructor.

Also this type should not be ABI affecting, but w/e.

ldionne requested changes to this revision.Mar 18 2022, 10:56 AM
This revision now requires changes to proceed.Mar 18 2022, 10:56 AM