Skip to content

clang-format removes newline after "private:" #55132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zmodem opened this issue Apr 27, 2022 · 5 comments
Closed

clang-format removes newline after "private:" #55132

zmodem opened this issue Apr 27, 2022 · 5 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior clang-format

Comments

@zmodem
Copy link
Collaborator

zmodem commented Apr 27, 2022

Consider:

$ cat /tmp/a.cc
#include <memory>

class A {
 public:
  std::unique_ptr<const char* []> b() {
    return nullptr;
  }

 private:
  int c_ = 0;
};

$ build.release/bin/clang-format -style="{BasedOnStyle: Chromium, Standard: c++17}" /tmp/a.cc
#include <memory>

class A {
 public:
  std::unique_ptr<const char* []> b() { return nullptr; }

  private : int c_ = 0;
};

Note the missing newline after private: and extra space before the colon. That seems like a bug.

(Originally from https://bugs.chromium.org/p/chromium/issues/detail?id=1320172)

@zmodem
Copy link
Collaborator Author

zmodem commented Apr 27, 2022

The style is not important, this reproduces also with -style="{}".
I tried running revisions back to sometime in 2017, but always with the same result, so this doesn't look like a regression.

@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2022

@llvm/issue-subscribers-clang-format

@mkurdej
Copy link
Member

mkurdej commented Apr 27, 2022

This bug is indeed present since at least release 3.7.

It seems to happen only with [] inside the return type.

E.g. this gets formatted ok:

class A {
  char * b() { return {}; }

private:
  int c_ = 0;
};

But not this:

class A {
  char *[] b() { return {}; }

  private : int c_ = 0;
};

@owenca owenca added the bug Indicates an unexpected problem or unintended behavior label Apr 27, 2022
@owenca owenca self-assigned this Apr 27, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2022

@llvm/issue-subscribers-bug

@owenca
Copy link
Contributor

owenca commented Apr 28, 2022

@owenca owenca added the awaiting-review Has pending Phabricator review label Apr 28, 2022
@owenca owenca closed this as completed in c8603db May 2, 2022
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-format
Projects
None yet
Development

No branches or pull requests

5 participants