Issue 166592
Summary [clang-format] Error formatting class with MSVC export class prefix but without constructor
Labels clang-format
Assignees
Reporter lovehina13
    Assuming the following code (single file, each case defined):

```cpp
#pragma once

#ifdef MYEXPORTS
#define MYEXPORT __declspec(dllexport)
#else
#define MYEXPORT __declspec(dllimport)
#endif

class MyClass {
  public:
    static inline bool get() { return true; }
    MyClass() = default;
};

class MyClass {
  public:
    static inline bool get() { return true; }
};

class MYEXPORT MyClass {
  public:
    static inline bool get() { return true; }
    MyClass() = default;
};

class MYEXPORT MyClass {
 public:
    static inline bool get() { return true; }
};
```

Applying clang-format 19.1.7 with default parameters get the following code:

```cpp
// ...

class MyClass {
  public:
    static inline bool get() { return true; }
    MyClass() = default;
};

class MyClass {
 public:
    static inline bool get() { return true; }
};

class MYEXPORT MyClass {
  public:
    static inline bool get() { return true; }
 MyClass() = default;
};

class MYEXPORT MyClass{public: static inline bool get(){ return true;
}
}
;
```

The class definition with `MYEXPORT` prefix but without constructor fails at formatting.
Then, since the `{` character is attached to the class name, it's not considered as a class (but initializer-list) and the definition fails.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to