Given files:
./_clang-format
./code/_clang-format
./code/raw_string_with_cpp_content.cpp
./_clang-format contains:
---
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 0
...
./code/_clang-format contains:
---
BasedOnStyle: InheritParentConfig
---
Language: Cpp
ColumnLimit: 100
...
./code/raw_string_with_cpp_content.cpp contains:
#include <string>
extern std::string foo(void);
std::string foo(void) {
std::string s = R"CPP(
int foo(int x) {
int y = x *2;
int c = 0;
while (y > 0) {
if (y > 10) {
y -= 2;
} else {
y--;
}
c++;
}
return c;
}
)CPP";
return s;
}
Running clang-format 21.1 (I used 21.1.1 via /path/to/llvm-21.1/clang-format -style=file code/raw_string_with_cpp_content.cpp >code/out.21.1.run.cpp) yields:
#include <string>
extern std::string foo(void);
std::string foo(void) {
std::string s = R"CPP(
int foo(int x) {
int y = x * 2;
int c = 0;
while (y > 0) {
if (y > 10) {
y -= 2;
} else {
y--;
}
c++;
}
return c;
}
)CPP";
return s;
}
Running clang-format 22.1 (I used 22.1.4 via /path/to/llvm-22.1/clang-format -style=file code/raw_string_with_cpp_content.cpp >code/out.22.1.run.cpp) yields:
#include <string>
extern std::string foo(void);
std::string foo(void) {
std::string s = R"CPP(
int foo(int x) {
int y = x * 2;
int c = 0;
while (y > 0) {
if (y > 10) {
y -= 2;
} else {
y--;
}
c++;
}
return c;
}
)CPP";
return s;
}
Notice that the "IndentWidth: 4" is no longer honored with clang-format 22.1. This problem
occurs when using "BasedOnStyle: InheritParentConfig" as shown. If I merge the two _clang-format
files into one, the we get the expected results.
Given files:
./_clang-formatcontains:./code/_clang-formatcontains:./code/raw_string_with_cpp_content.cppcontains:Running clang-format 21.1 (I used 21.1.1 via
/path/to/llvm-21.1/clang-format -style=file code/raw_string_with_cpp_content.cpp >code/out.21.1.run.cpp) yields:Running clang-format 22.1 (I used 22.1.4 via
/path/to/llvm-22.1/clang-format -style=file code/raw_string_with_cpp_content.cpp >code/out.22.1.run.cpp) yields:Notice that the "IndentWidth: 4" is no longer honored with clang-format 22.1. This problem
occurs when using "BasedOnStyle: InheritParentConfig" as shown. If I merge the two _clang-format
files into one, the we get the expected results.