Issue 80374
Summary Include Regrouping May Break If Macros Inserted Between Groups
Labels new issue
Assignees
Reporter GreenYun
    I have configured clang-format:

```yaml
IncludeBlocks: Regroup
IncludeCategories:
  - Regex: '^["<]config.h[">]$'
    Priority:        -1
    CaseSensitive: true
  - Regex:           '^<ext/.*\.h>$'
    Priority:        2
 CaseSensitive:   false
  - Regex:           '^<.*'
    Priority: 2
    CaseSensitive:   false
  - Regex:           '.*'
 Priority:        10
    CaseSensitive:   false
```

And my C code `a.c`:

```c
#include "config.h"

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include "a.h"

#include <stdio.h>
#include <stdlib.h>

#include "b.h"
```

However, clang-format (version 17.0.6) may not treat `a.h` as the main header but match `a.h` to regex `'.*'`:

```c
#include "config.h"

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <stdio.h>
#include <stdlib.h>

#include "a.h"
#include "b.h"
```

Meanwhile, if I remove the `#ifndef` block, everything works fine.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to