| Issue |
202597
|
| Summary |
clang-format behaves strangely when macros are used for class and ctor-definitions
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
pboettch
|
Take this minimalized example (simplified of what we are doing in reality).
```C++
#include <iostream>
#define OUR_CLASS_DEF(__t) class __t ## _yo
#define OUR_CTOR_DEF(__t) __t ## _yo()
OUR_CLASS_DEF(hello)
{
public:
OUR_CTOR_DEF(hello) {
std::cout << "hello World!\n";
}
void f() {
int a = 0;
int c = 3;
}
};
```
clang-formatting it with clang-format-22 and `BasedOn: LLVM` gives a broken formatted output:
```
#include <iostream>
#define OUR_CLASS_DEF(__t) class __t##_yo
#define OUR_CTOR_DEF(__t) __t##_yo()
OUR_CLASS_DEF(hello){public : OUR_CTOR_DEF(hello){std::cout << "hello World!\n";
}
void f() {
int a = 0;
int c = 3;
}
}
;
```
Adding a variable-member to the class before `public:` fixes the formatting:
```C++
#include <iostream>
#define OUR_CLASS_DEF(__t) class __t##_yo
#define OUR_CTOR_DEF(__t) __t##_yo()
OUR_CLASS_DEF(hello) {
int i;
public:
OUR_CTOR_DEF(hello) { std::cout << "hello World!\n"; }
void f() {
int a = 0;
int c = 3;
}
};
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs