llvm / llvm-project

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

[bug] clang-tidy `modernize-concat-nested-namespaces` and macros #83452

Open r-barnes opened 6 months ago

r-barnes commented 6 months ago

When using modernize-concat-nested-namespaces in clang-tidy this:

namespace MY_NAMESPACE_MACRO {
namespace nested {

} // nested 
} // MY_NAMESPACE_MACRO

gets rewritten as

namespace my_namespace::nested {

} // my_namespace::nested 

but the appropriate rewrite is

namespace MY_NAMESPACE_MACRO::nested {

} // MY_NAMESPACE_MACRO::nested 
mzyKi commented 6 months ago

I test in latest version and get the following result:

    1 | namespace MY_NAMESPACE_MACRO {
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 | namespace nested {
      | ~~~~~~~~~~~~~~~~
      | namespace MY_NAMESPACE_MACRO::nested
    3 | 
    4 | } // nested 
    5 | } // MY_NAMESPACE_MACRO

But when I apply --fix, it will be like this:


// MY_NAMESPACE_MACRO

only comment

IndifferentArea commented 1 month ago

I found a similar bug

namespace A {

#define MACRO

namespace B {

}  // B
}  // A

will get rewritten as

namespace A::B {

}  // A::B

the macro is deleted.