[PATCH] D75364: [clang-format] Handle macros in function params and return value

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 6 05:22:30 PDT 2020


krasimir added a comment.

A sample of snippets that this misformats:

- inside other macro:

  EXPECT_EQ(Calc()* bar, baz);

- in member function call:

  BENCHMARK(BM_Foo)->ThreadRange(1, NumCPUs()* 2);

- this causes javascript diffs:

  - const foo = (bar == 'rtl' ? -1 : 1) * (blah || blah || 0);
  + const foo =(bar == 'rtl' ? -1 : 1) * (blah || blah || 0);

- binary operators with casts:

  a = (int)(b()* c);
  rectaaaaaaaaaaaaaa->SetSize((int)(GetWidth(foo)* bar),
                              (int)(GetHeight(foo)* bar));
  int f() {
    ...
  - return static_cast<int>(param) * (a * b + c);
  + return static_cast<int>(param)*(a * b + c);
  }



- some arithmetic expressions:

  float aaaa = 43 * log(sin(a/4) *b);

Test:

  % cat test.cc                           
  EXPECT_EQ(Calc() * bar, baz);
  
  BENCHMARK(BM_Foo)->ThreadRange(1, NumCPUs() * 2);
  
  a = (int)(b() * c);
  
  rectaaaaaaaaaaaaaa->SetSize((int)(GetWidth(foo) * bar),
                              (int)(GetHeight(foo) * bar));
  
  int f() { return static_cast<int>(param) * (a * b + c); }
  
  float aaaa = 43 * log(sin(a / 4) * b);
  % bin/clang-format -style=google test.cc
  EXPECT_EQ(Calc()* bar, baz);
  
  BENCHMARK(BM_Foo)->ThreadRange(1, NumCPUs()* 2);
  
  a = (int)(b()* c);
  
  rectaaaaaaaaaaaaaa->SetSize((int)(GetWidth(foo)* bar),
                              (int)(GetHeight(foo)* bar));
  
  int f() { return static_cast<int>(param)*(a * b + c); }
  
  float aaaa = 43 * log(sin(a / 4)* b);
  % cat test.js
  const foo = (bar == 'rtl' ? -1 : 1) * (blah || blah || 0);
  % bin/clang-format -style=google test.js
  const foo =(bar == 'rtl' ? -1 : 1) * (blah || blah || 0);


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75364/new/

https://reviews.llvm.org/D75364





More information about the cfe-commits mailing list