llvm / llvm-project

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

Inconsistent indentation #80981

Open HFriberg opened 4 months ago

HFriberg commented 4 months ago

When I format

#ifdef __cplusplus
extern "C"
{
#endif

#if 0
typedef int myint;
  typedef double mydouble;
#endif

#if 1
#else
typedef int myint2;
  typedef double mydouble2;
#endif

typedef int myint3;
  typedef double mydouble3;

#ifdef __cplusplus
} /* extern "C" */
#endif

I get

#ifdef __cplusplus
extern "C"
{
#endif

#if 0
typedef int myint;
  typedef double mydouble;
#endif

#if 1
#else
typedef int myint2;
typedef double mydouble2;
#endif

  typedef int myint3;
  typedef double mydouble3;

#ifdef __cplusplus
} /* extern "C" */
#endif

1) Why is formatting inactive in the #if 0 block, but active in the #if 1 ... #else block?

2) Why is the indentation of myint2 and mydouble2 inconsistent with the indentation of myint3 and mydouble3?


My .clang-format style is

BasedOnStyle: LLVM
BreakBeforeBraces: Allman
llvmbot commented 4 months ago

@llvm/issue-subscribers-clang-format

Author: Henrik Alsing Friberg (HFriberg)

When I format ```c #ifdef __cplusplus extern "C" { #endif #if 0 typedef int myint; typedef double mydouble; #endif #if 1 #else typedef int myint2; typedef double mydouble2; #endif typedef int myint3; typedef double mydouble3; #ifdef __cplusplus } /* extern "C" */ #endif ``` I get ```c #ifdef __cplusplus extern "C" { #endif #if 0 typedef int myint; typedef double mydouble; #endif #if 1 #else typedef int myint2; typedef double mydouble2; #endif typedef int myint3; typedef double mydouble3; #ifdef __cplusplus } /* extern "C" */ #endif ``` 1) Why is formatting inactive in the `#if 0` block, but active in the `#if 1 ... #else` block? 2) Why is the indentation of `myint2` and `mydouble2` inconsistent with the indentation of `myint3` and `mydouble3`? --- My `.clang-format` style is ``` BasedOnStyle: LLVM BreakBeforeBraces: Allman ```