Skip to content

Conversation

@sstwcw
Copy link
Contributor

@sstwcw sstwcw commented Oct 22, 2025

after, with style {ColumnLimit: 60}

[objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)];

before

[objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)];

Fixes #164574.

The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.

after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-clang-format

Author: None (sstwcw)

Changes

after, with style {ColumnLimit: 60}

[objectName respondsToSelector: @<!-- -->selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)];

before

[objectName respondsToSelector: @<!-- -->selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)];

Fixes #164574.

The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.


Full diff: https://github.com/llvm/llvm-project/pull/164674.diff

2 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+9-3)
  • (modified) clang/unittests/Format/FormatTestObjC.cpp (+6)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c97a9e81eb59e..1d0dfd0b9c151 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4407,8 +4407,12 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, // breaking after it. if (Right.is(TT_SelectorName)) return 0; - if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) - return Line.MightBeFunctionDecl ? 50 : 500; + if (Left.is(tok::colon)) { + if (Left.is(TT_ObjCMethodExpr)) + return Line.MightBeFunctionDecl ? 50 : 500; + if (Left.is(TT_ObjCSelector)) + return 500; + } // In Objective-C type declarations, avoid breaking after the category's // open paren (we'll prefer breaking after the protocol list's opening @@ -6291,7 +6295,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, TT_BitFieldColon)) { return false; } - if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) { + if (Left.is(tok::colon) && Left.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr)) + return true; + if (Left.is(tok::colon) && Left.is(TT_DictLiteral)) { if (Style.isProto()) { if (!Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral()) return false; diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 700d7cf8efca6..cf8143ace7b45 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -949,6 +949,12 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) { "[aaaaaaaaaaaaaaaaaaaaaaaaa\n" " aaaaaaaaaaaaaaaaa:aaaaaaaa\n" " aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];"); + verifyFormat("[objectName\n" + " respondsToSelector:\n" + " @selector(\n" + " somelonglonglonglongnameeeeeeee:\n" + " loooooooooanotherlonglonglonglongnametopush:\n" + " otherlongnameforlimit:)];"); Style = getChromiumStyle(FormatStyle::LK_ObjC); Style.ColumnLimit = 80; 
@sstwcw sstwcw merged commit 53b9441 into llvm:main Oct 23, 2025
12 checks passed
@sstwcw sstwcw deleted the format-objc-selector branch October 23, 2025 13:17
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 23, 2025

LLVM Buildbot has detected a new failure on builder cross-project-tests-sie-ubuntu running on doug-worker-1a while building clang at step 6 "test-build-unified-tree-check-cross-project".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/181/builds/30394

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-cross-project) failure: test (failure) ... UNSUPPORTED: cross-project-tests :: debuginfo-tests/dexter/feature_tests/commands/perfect/dex_declare_file/dex_and_source/test.cpp (135 of 144) UNSUPPORTED: cross-project-tests :: amdgpu/builtins-amdgcn-swmmac-w32.cl (136 of 144) UNSUPPORTED: cross-project-tests :: amdgpu/builtins-amdgcn-swmmac-w64.cl (137 of 144) UNSUPPORTED: cross-project-tests :: amdgpu/builtins-amdgcn-wmma-w32.cl (138 of 144) PASS: cross-project-tests :: debuginfo-tests/dexter/feature_tests/unittests/run.test (139 of 144) XFAIL: cross-project-tests :: debuginfo-tests/llgdb-tests/nested-struct.cpp (140 of 144) PASS: cross-project-tests :: debuginfo-tests/dexter/feature_tests/subtools/help/help.test (141 of 144) PASS: cross-project-tests :: debuginfo-tests/clang_llvm_roundtrip/simplified_template_names_noncanonical_type_units.cpp (142 of 144) XFAIL: cross-project-tests :: debuginfo-tests/llgdb-tests/forward-declare-class.cpp (143 of 144) TIMEOUT: cross-project-tests :: debuginfo-tests/dexter-tests/optnone-loops.cpp (144 of 144) ******************** TEST 'cross-project-tests :: debuginfo-tests/dexter-tests/optnone-loops.cpp' FAILED ******************** Exit Code: -9 Timeout: Reached timeout of 900 seconds Command Output (stderr): -- /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/bin/clang++ -std=gnu++11 -O2 -g /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter-tests/optnone-loops.cpp -o /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/projects/cross-project-tests/debuginfo-tests/dexter-tests/Output/optnone-loops.cpp.tmp # RUN: at line 8 + /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/bin/clang++ -std=gnu++11 -O2 -g /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter-tests/optnone-loops.cpp -o /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/projects/cross-project-tests/debuginfo-tests/dexter-tests/Output/optnone-loops.cpp.tmp "/usr/bin/python3.8" "/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter/dexter.py" test -v --fail-lt 1.0 -w --binary /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/projects/cross-project-tests/debuginfo-tests/dexter-tests/Output/optnone-loops.cpp.tmp --lldb-executable "/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/bin/lldb-dap" --debugger lldb-dap --dap-message-log=-e -- /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter-tests/optnone-loops.cpp # RUN: at line 9 + /usr/bin/python3.8 /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter/dexter.py test -v --fail-lt 1.0 -w --binary /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/projects/cross-project-tests/debuginfo-tests/dexter-tests/Output/optnone-loops.cpp.tmp --lldb-executable /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/bin/lldb-dap --debugger lldb-dap --dap-message-log=-e -- /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/cross-project-tests/debuginfo-tests/dexter-tests/optnone-loops.cpp note: Opening DAP server: /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/build/bin/lldb-dap -> { "type": "request", "command": "initialize", "arguments": { "clientID": "dexter", "adapterID": "lldb-dap", "pathFormat": "path", "linesStartAt1": true, "columnsStartAt1": true, "supportsVariableType": true, "supportsVariablePaging": true, "supportsRunInTerminalRequest": false }, "seq": 1 } <- { "body": { "$__lldb_version": "lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision 53b9441f5355fcdca07dc5b6ddc4fa5bb7ce4920)\n clang revision 53b9441f5355fcdca07dc5b6ddc4fa5bb7ce4920\n llvm revision 53b9441f5355fcdca07dc5b6ddc4fa5bb7ce4920", "completionTriggerCharacters": [ ".", " ", "\t" ], "exceptionBreakpointFilters": [ { "description": "C++ Catch", "filter": "cpp_catch", "label": "C++ Catch", 
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
after, with style `{ColumnLimit: 60}` ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee: loooooooooanotherlonglonglonglongnametopush: otherlongnameforlimit:)]; ``` before ```Objective-C [objectName respondsToSelector: @selector( somelonglonglonglongnameeeeeeee:loooooooooanotherlonglonglonglongnametopush:otherlongnameforlimit:)]; ``` Fixes llvm#164574. The stuff inside the parentheses got a new type in 2a05904. I neglected to add it to the logic for breaking lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants