This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Add an option to add a space between operator overloading and opening parentheses
ClosedPublic

Authored by rajatbajpai on Dec 26 2021, 3:27 AM.

Details

Summary

This change adds an option AfterOverloadedOperator in SpaceBeforeParensOptions to add a space between overloaded operator and opening parentheses in clang-format.

Diff Detail

Event Timeline

rajatbajpai requested review of this revision.Dec 26 2021, 3:27 AM
rajatbajpai created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 26 2021, 3:27 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

you need to add a unit test int clang/unittest/Format/FormatTest.cpp (we tend to not use lit tests)

MyDeveloperDay requested changes to this revision.Dec 26 2021, 6:35 AM
This revision now requires changes to proceed.Dec 26 2021, 6:35 AM
clang/include/clang/Format/Format.h
3452

Please put the vs. on the same column as the others.

3455

Please sort alphabetical.

clang/lib/Format/Format.cpp
874

Sort

Incorporated review comments.

Changelog:

  1. Using unit test case instead of lit test case.
  2. Placed the option according to alphabetical order.
rajatbajpai marked 3 inline comments as done.Dec 27 2021, 7:02 AM

Fixed the patch file.

MyDeveloperDay added inline comments.Dec 28 2021, 6:56 AM
clang/unittests/Format/FormatTest.cpp
14539

There should be a PARSE unit test too please

14540
curdeius retitled this revision from Added an option to add a space between operator overloading and opening parentheses in clang-format to [clang-format] Add an option to add a space between operator overloading and opening parentheses.Dec 28 2021, 10:30 AM
curdeius added inline comments.Dec 28 2021, 10:34 AM
clang/docs/ClangFormatStyleOptions.rst
3821

I'm not fond of the current name, exactly the "Overloading" part (but have no better suggestion right now). It seems a bit misleading to me.

Maybe AfterOverloadedOperator(Name)??? At least it would match the token kind name.

clang/docs/ClangFormatStyleOptions.rst
3821

+1 here, AfterOperator?

Does it affect calling code? a.operator++(5); Should it? But please add tests for that.

Does it affect calling code? a.operator++(5); Should it? But please add tests for that.

Yes, it does affect the calling code as well. However, I am not sure if we should separate the two. Sure, I'll add a test case for it.

clang/docs/ClangFormatStyleOptions.rst
3821

@MyDeveloperDay Initially, I thought about using AfterOperator but it also seems a bit misleading. However, @curdeius suggestion seems reasonable given it matches with the token kind.

rajatbajpai added inline comments.Dec 30 2021, 8:59 AM
clang/unittests/Format/FormatTest.cpp
14539

I'm sorry if I misunderstood it, do you mean tests using CHECK_PARSE? I am confirming this because I didn't find any such test case for existing SpaceBeforeParensOptions options.

clang/unittests/Format/FormatTest.cpp
14539

Than this has slipped through, but there should be a test for every parsing aspect.

rajatbajpai added inline comments.Dec 31 2021, 5:12 AM
clang/unittests/Format/FormatTest.cpp
14539

Thanks for confirming.

Not an issue, I'll try to add a test case for existing options as well then.

Incorporated review comments.

  1. Added Check Parse test case for SpaceBeforeParensOptions.
  2. Renamed the option to AfterOverloadedOperator.
  3. Added operator overloading instantiation scenario in the unit test as well.
rajatbajpai marked 5 inline comments as done.Jan 2 2022, 4:34 AM
MyDeveloperDay accepted this revision.Jan 2 2022, 5:58 AM

LGTM, could you add a release note into docs/ReleaseNotes.rst?

This revision is now accepted and ready to land.Jan 2 2022, 5:58 AM
curdeius added inline comments.Jan 3 2022, 2:47 AM
clang/docs/ClangFormatStyleOptions.rst
3826

Please add operator call as well to the example (object.operator++ (0)).

LGTM, could you add a release note into docs/ReleaseNotes.rst?

Sure, will do.

clang/docs/ClangFormatStyleOptions.rst
3826

Sure, will add.

Incorporated review comments.

Updated release note and example scenario.

rajatbajpai marked an inline comment as done.Jan 3 2022, 11:21 AM
curdeius accepted this revision.Jan 3 2022, 12:04 PM

LGTM.
If you need help landing this (if you don't have commit rights), just give your name and email that you want to be used for the contribution and someone will land it for you.

See also https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access if you think contributing more patches.

Thanks for adding the parse checks.

Thanks for adding the parse checks.

Not an issue :)

LGTM.
If you need help landing this (if you don't have commit rights), just give your name and email that you want to be used for the contribution and someone will land it for you.

See also https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access if you think contributing more patches.

Thanks everyone for taking time to review this change.

Yes, I don't have commit rights. Please land this change for me (name : Rajat Bajpai and email: rb.macboy@gmail.com).

I will apply for commit access for future changes.

curdeius edited the summary of this revision. (Show Details)Jan 4 2022, 8:22 AM
This revision was landed with ongoing or failed builds.Jan 4 2022, 8:23 AM
This revision was automatically updated to reflect the committed changes.