llvm / llvm-project

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

[clang-tidy] modernize-macro-to-enum can create invalid syntax in header files #54885

Open LegalizeAdulthood opened 2 years ago

LegalizeAdulthood commented 2 years ago

modernize-macro-to-enum creates a bunch of little insertions around a cluster of macros to turn this:

#define FOO1 1
#define FOO2 2
#define FOO3 3

into this

enum {
FOO1 = 1,
FOO2 = 2,
FOO3 = 3
};

The problem is that when the fixes are exported, the insertions of the = are not de-duplicated by clang-apply-replacements. So if clang-tidy is run with header-filter set to apply to application header files, the header files that have fixits issued in the course of analyzing multiple source files end up with invalid syntax llike this:

enum {
FOO1 = = 1,
FOO2 = = 2,
FOO3 = = 3
};
};

The fixes need to be recorded in such a way that they can be properly de-duplicated.

llvmbot commented 2 years ago

@llvm/issue-subscribers-bug

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-tidy