llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

[clang-tidy] Key 'bugprone-macro-parentheses' breaks the code #53513

Open shrek1402 opened 2 years ago

shrek1402 commented 2 years ago

Before:

#define CREATE_AND_DECLARE_PAIR(pair_name)                                                                             \
  template<class Ty1, class Ty2>                                                                                       \
  struct pair_name {                                                                                                   \
      pair_name& operator=(const pair_name&) = default;                                                                \
      pair_name& operator=(pair_name&&) noexcept = default;                                                            \
  }

After:

#define CREATE_AND_DECLARE_PAIR(pair_name)                                                                             \
  template<class Ty1, class Ty2>                                                                                       \
  struct pair_name {                                                                                                   \
      (pair_name) & operator=(const pair_name&) = default;                                                             \
      (pair_name) & operator=((pair_name) &&) noexcept = default;                                                      \
  }

(pair_name) & operator= there is an error due to parentheses.

shrek1402 commented 2 years ago

I use this command: clang-tidy.exe -fix test.cpp -- -std=c++17

llvmbot commented 2 years ago

@llvm/issue-subscribers-bug

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-tidy

JonasToth commented 2 years ago

Whats interesting is the missing parenthesis in the copy-assignment parameter.

In general: Macros are working on just tokens. That means it is not possible to detect if the thing you are inserting to is a type-name or a variable name. This is the reason why C++ tries to get rid of macros and replace them with e.g. meta-classes.

I am not sure if this is even possible to fix in clang-tidy. But it needs to be understood why the parens are not present in the copy assignment parameter.

I am afraid that you must silence this warning manually with NOLINT or NOLINTNEXTLINE (see clang-tidy docs for reference)