This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Support function and overloaded operator SpacesInParensOption
Needs ReviewPublic

Authored by gedare on Jul 26 2023, 12:57 PM.

Details

Summary

This change separates function calls, declarations, definitions, and
overloaded operators from SpacesInParensOptions.Other to allow control
over each independently.

Fixes Github Issue #55428. https://github.com/llvm/llvm-project/issues/55428

Depends on D155529

Event Timeline

gedare created this revision.Jul 26 2023, 12:57 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJul 26 2023, 12:57 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gedare requested review of this revision.Jul 26 2023, 12:57 PM
gedare edited the summary of this revision. (Show Details)Jul 26 2023, 12:58 PM

You need some tests to show that the new options really apply like intended.

gedare updated this revision to Diff 544544.Jul 26 2023, 3:55 PM

Add tests and correct function call detection.

clang/unittests/Format/FormatTest.cpp
16714–16715

Why change this?

16833

Should here be a space?

gedare added inline comments.Aug 1 2023, 10:43 AM
clang/unittests/Format/FormatTest.cpp
16714–16715

The original test is incomplete/ambiguous. It's either a declaration missing a semicolon, or it's the start of a definition. I made it a definition.

16833

That's controlled by space in empty parens.

owenpan added inline comments.Nov 9 2023, 4:23 PM
clang/lib/Format/TokenAnnotator.cpp
3969–4010

Consider wrapping this in a function or lambda. Not sure if it would simply the logic with the parens being handled separately:

if (Left.is(tok::l_paren)) {
  ...
} else if (Right.is(tok::r_paren)) {
  ...
}
3988

No else after return.

clang/unittests/Format/FormatTest.cpp
16714–16715

Then can you also add a declaration?

gedare updated this revision to Diff 558245.Tue, Dec 19, 6:15 PM

Fix for review comments, refactor logic to lambdas

gedare updated this revision to Diff 558246.Tue, Dec 19, 6:26 PM

add missing test case for function prototype

gedare marked 3 inline comments as done.Tue, Dec 19, 6:28 PM