This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Support non-trivial defaulted special member functions in Define Outline tweak
AcceptedPublic

Authored by njames93 on Apr 7 2023, 1:10 PM.

Details

Summary

Sometimes classes can't have a defaulted or empty special member function declared inside the class if any of the members have forward declared types as template parameters.
The Pimpl idiom is a classic example of this
In these situations it makes sense to have a defaulted special member function moved to the source file. Currently the define outline tweak will reject these defaulted special member functions.

Diff Detail

Event Timeline

njames93 created this revision.Apr 7 2023, 1:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2023, 1:10 PM
Herald added a subscriber: arphaman. · View Herald Transcript
njames93 requested review of this revision.Apr 7 2023, 1:10 PM
njames93 edited the summary of this revision. (Show Details)Apr 8 2023, 11:03 AM

there's actually a slight difference between an inline defaulted special member function and an out-of-line defaulted one. the latter makes the special member "user-defined" which might cause various headaches (e.g. type is no longer "trivial"). i don't think we should make it easy for people to change trivialness of types (especially considering our experience with people thinking anything that comes from the lightbulb is a way to improve your code). on a side node, this is less of an issue in the scenario you described (i.e. when the destructor is virtual, as it already means type is non-trivial).

so if you feel like this is really useful, i guess we can change the scope a little to apply to all special members, but only when type is no longer trivial. WDYT?

there's actually a slight difference between an inline defaulted special member function and an out-of-line defaulted one. the latter makes the special member "user-defined" which might cause various headaches (e.g. type is no longer "trivial"). i don't think we should make it easy for people to change trivialness of types (especially considering our experience with people thinking anything that comes from the lightbulb is a way to improve your code). on a side node, this is less of an issue in the scenario you described (i.e. when the destructor is virtual, as it already means type is non-trivial).

so if you feel like this is really useful, i guess we can change the scope a little to apply to all special members, but only when type is no longer trivial. WDYT?

That makes sense.

njames93 updated this revision to Diff 513669.Apr 14 2023, 10:29 AM

Updated to work on all special member functions as long as they aren't trivial

njames93 retitled this revision from [clangd] Support defaulted destructors in Define Outline tweak to [clangd] Support non-trivial defaulted special member functions in Define Outline tweak.Apr 14 2023, 10:31 AM
njames93 edited the summary of this revision. (Show Details)
njames93 updated this revision to Diff 513862.Apr 15 2023, 2:04 AM
njames93 edited the summary of this revision. (Show Details)

Fix unittest, tests had trivial and non trivial mixed up

njames93 updated this revision to Diff 519496.May 4 2023, 7:58 AM

Fix clang-format issues. Ping?

kadircet accepted this revision.May 19 2023, 9:59 AM

thanks a lot, and sorry for the delay!

clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
333

can you add a comment here saying // We should have just `= default` in this case

409

i know i asked for triviality check in the first version, but thinking a little bit more about it, users might be more confused about code action's availability. as this is very subtle at a glance for anyone but the compiler. so i think it's better to just emit it always.

This revision is now accepted and ready to land.May 19 2023, 9:59 AM