llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

wrong fix of clang-tidy bugprone-macro-parentheses

Open jackua22 opened this issue 2 years ago • 0 comments

In this program

#define my_cast(type, p) reinterpret_cast<type*>(p)

void foo(void *p)
{
    (void)my_cast(int, p);
}

This command % /grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang-tidy --fix --checks=bugprone-macro-parentheses bugprone-macro-parentheses.cpp -- -std=c++17 -stdlib=libc++ converts the macro to #define my_cast(type, p) (reinterpret_cast<(type)*>(p)) And then the compilation fails

% /grid/common/test/llvm-v17.0.6d1rh74_lnx86/bin/clang++ -c -std=c++17 -stdlib=libc++ bugprone-macro-parentheses.cpp
bugprone-macro-parentheses.cpp:10:11: error: expected a type
    5 |     (void)my_cast(int, p);
      |           ^
bugprone-macro-parentheses.cpp:6:44: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      |                                            ^
bugprone-macro-parentheses.cpp:10:11: error: expected '>'
bugprone-macro-parentheses.cpp:6:50: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      |                                                  ^
bugprone-macro-parentheses.cpp:10:11: note: to match this '<'
bugprone-macro-parentheses.cpp:6:43: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      |                                           ^
bugprone-macro-parentheses.cpp:10:11: error: expected expression
    5 |     (void)my_cast(int, p);
      |           ^
bugprone-macro-parentheses.cpp:6:51: note: expanded from macro 'my_cast'
    1 | #define my_cast(type, p) (reinterpret_cast<(type)*>(p))
      |                                                   ^
3 errors generated.

jackua22 avatar May 05 '24 23:05 jackua22