Skip to content

[clang-format] mistaking reference for binary operator in macro with clang-format 19 #100304

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
rmarker opened this issue Jul 24, 2024 · 4 comments

Comments

@rmarker
Copy link
Contributor

rmarker commented Jul 24, 2024

While trying out clang-format on the new 19.x branch, I discovered an issue with the formatting in macros.
It is incorrectly treating the rvalue reference as a binary operator.

In clang-format 18.1.7 with the default LLVM style:

#define RVALUE_COPY(CLASS)                                                     \
  CLASS(CLASS &&That) : my(std::move(That.my)) {}

In clang-format 19.1.0 (183e8ec)

#define RVALUE_COPY(CLASS)                                                     \
  CLASS(CLASS && That) : my(std::move(That.my)) {}

I also discovered that a similar thing happens with * and & as well. I.e.

#define PTR_COPY(CLASS)                                                     \
  CLASS(CLASS * That) : my(That->my) {}
#define REF_COPY(CLASS)                                                     \
  CLASS(CLASS & That) : my(That.my) {}
@owenca owenca self-assigned this Jul 24, 2024
@owenca
Copy link
Contributor

owenca commented Jul 24, 2024

Bisected to ce1a874.

@rmarker
Copy link
Contributor Author

rmarker commented Jul 24, 2024

While continuing to try out the new version, I've come across several more instances which could be the same issue.

clang-format 18.1.7

#define MACRO(MYTYPE)                                                          \
  template <> bool foo<MYTYPE>::bar(MYTYPE *Value, bool B) const {}

#define MACRO() template <typename... ARGS> Test(ARGS &&...);

#define MACRO() Foo(Foo &&That) noexcept;

#define MACRO(NAMESPACE) Foo fun_##NAMESPACE##_tion(Bar *Value);

clang-format 19.1.0

#define MACRO(MYTYPE)                                                          \
  template <> bool foo<MYTYPE>::bar(MYTYPE * Value, bool B) const {}

#define MACRO() template <typename... ARGS> Test(ARGS && ...);

#define MACRO() Foo(Foo && That) noexcept;

#define MACRO(NAMESPACE) Foo fun_##NAMESPACE##_tion(Bar * Value);

@owenca owenca added this to the LLVM 19.X Release milestone Jul 25, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 25, 2024
@owenca owenca closed this as completed in 7e7a906 Jul 25, 2024
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in LLVM Release Status Jul 25, 2024
@owenca
Copy link
Contributor

owenca commented Jul 25, 2024

/cherry-pick 7e7a906

@owenca owenca reopened this Jul 25, 2024
@github-project-automation github-project-automation bot moved this from Done to Needs Triage in LLVM Release Status Jul 25, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Jul 25, 2024
@llvmbot llvmbot closed this as completed Jul 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

/pull-request #100499

@github-project-automation github-project-automation bot moved this from Needs Triage to Done in LLVM Release Status Jul 25, 2024
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
)"

Summary:
This reverts commit ce1a874.

Closes #100304.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250538
tru pushed a commit to llvmbot/llvm-project that referenced this issue Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

4 participants