906 questions
1
vote
0
answers
33
views
Clang format prefer break on parameter list over trailing return type
I'm trying to setup clang-format but am having issues with a particular behavior. Basically, I want clang-format to prefer breaking function parameter lists over anything else, even if it's empty.
How ...
0
votes
1
answer
45
views
Split function/parameters if they can't all be on the same line as the parentheses
I want to get this style for function parameters/arguments:
// If they fit on one line:
bar(a, b, c);
// If not, break them all:
bar(
a,
b,
c
);
You can get pretty close with these widely-...
3
votes
1
answer
123
views
Does clang-format always reformat array initializers?
Suppose I have a file test.c with the content below. I as a developer have formatted my firmware blob with 8 bytes per line so that when I want to find the byte at offset 0x25 I can easily locate it.
#...
4
votes
1
answer
157
views
How to configure .clang-format to indent access modifiers in a class definition?
I want my C++ class definitions to have access modifiers indented like below:
class Foo
{
public:
Foo(Bar bar);
Foo(Bar *bar);
};
Foo::Foo(Bar bar)
{
if ()
{
while ()
{
}
}...
0
votes
0
answers
122
views
clang-format ignores SpaceBeforeCpp11BracedList and Cpp11BracedListStyle
I’m using CLion and trying to make it insert a space before C++11-style braced-init-lists while keeping the “Cpp11” list style.
According to the docs both
SpaceBeforeCpp11BracedList: true
...
0
votes
0
answers
59
views
VS Code C++ Formatting - Leave blank line before closing bracket
I am writing C++ in the VS Code app, and am trying to customize the formatting so that it matches the formatting in Visual Studio.
In Visual Studio, the formatting of a function looks like this:
void ...
-1
votes
0
answers
49
views
.clang-format not putting item on new line [duplicate]
The following is my .clang-format file:
IndentWidth: 2
IndentCaseLabels: true
AllowShortEnumsOnASingleLine: false
ColumnLimit: 100
BinPackArguments: false
BinPackParameters: false
...
-1
votes
0
answers
14
views
Formatting doxygen-style function description with clang-format
Assuming we have a file with C code like this:
/**
* @brief Test function
*
* @param i One letter parameter
* @param many_words_here Parameter with long name
* @return error code or 0 for ...
0
votes
0
answers
83
views
How to format brace for array element into new line?
I have the following .clang-format:
---
BasedOnStyle: WebKit
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
ColumnLimit: 0
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
...
-7
votes
1
answer
191
views
Using both clang-format and cpplint leads to cpplint error
I have setup pre-commit hooks clang-format and cpplint for my C++ app.
The pre-commit command is pre-commit run -files test_main.cpp
The header include is in right order in original file
But clang-...
1
vote
1
answer
308
views
clang-format is not formatting files as expected
I am developing a Zephyr application and want to format all my source files to have the Zephyr coding style. I found the following .clang-format file in the Zephyr repository below. I put this in the ...
2
votes
1
answer
60
views
How to configure clang-format to align inline function declarations
i.e. How to configure clang-format to automatically format:
// Access Methods
inline T& operator[](size_t index) { return buffer[index]; }
inline T& Get(size_t index) { return buffer[index]; }
...
1
vote
0
answers
58
views
clang-format causing unnecessary line breaks after disallowing single line lambda
Code:
auto transs = transitions | stdv::filter([alph](const auto trns) { return trns.first == alph; })
| stdv::values | stdv::transform([](auto x) { return x; }) | stdv::as_rvalue;
...
0
votes
0
answers
52
views
clang format: break `) {` on multiline function header, and `{` for singleline
I want clang-format to break a function header on the ) {, when the parameters will be wrapped to newlines, like so:
void foo(
int a,
// ...
int b
) {
// ...
}
But when the parameters don't ...
0
votes
1
answer
97
views
Prevent clang-format from unwrapping struct definitions to a single line
New to clang-format so I might be missing something obvious.
But I don't like that it's forcing something like this:
typedef struct {
int a;
int b;
int c;
} my_struct_t;
into a single ...
2
votes
1
answer
126
views
Clang-format inconsistent formatting with struct initialization
Clang-format is behaving inconsistently when aligning a struct initialization. I would like the code to be formated like this:
struct RAMP ramp = {
ramp_init,
ramp_compute,
ramp_update,
...
0
votes
2
answers
159
views
Clang format - add space before angled bracket
I would like a space in-between std::unique_ptr and <boost::thread> in this line:
std::unique_ptr<boost::thread> my_thread;
You would think SpaceAfterTemplateKeyword: true would work, but ...
0
votes
1
answer
28
views
ClangFormat style to handle non-idiomatic whitespace?
Are there any ClangFormat styles (or other tools) which will handle excessive newlines? With two or more newlines after the function parameter parentheses, as in the example below, none of the styles ...
2
votes
0
answers
117
views
How to stop VS Code from wrongly indenting top level namespaces?
My clang_format mandates the following behavior:
namespace test
{
namespace inner
{
int test;
int test2;
} // namespace inner
namespace small
{
}
class MockSerializeWriter
{
};
} // ...
0
votes
0
answers
82
views
Unexpected include ordering and grouping using clang-format's IncludeCategories' Priority and SortPriority
I have the following .clang-format configuration file:
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<[a-z_]+>$' #1
Priority: 1
- Regex: '.*\/libalpha.h[">]$' #2.1
...
-2
votes
1
answer
107
views
Best practice for code snippet in doc comment for C project? [closed]
I'm familiar with Rust, and recently I'm going to write a C project. In Rust, we usually embed some code snippets as usage examples directly in the doc comment. However, I found this hard to be ...
0
votes
1
answer
657
views
Why does clang-format only format .c or .h files, but not both?
I am using clang-format in VS Code to format my C code on macOS, but I encountered a strange issue:
I have the following .clang-format configuration:
Language: C
BasedOnStyle: Google
and My VS Code ...
4
votes
0
answers
228
views
Bad Visual Studio Code indentation after pressing Enter
I'm using VSCode 1.96.4 on Windows with remote to Linux, clang-format 14.0.6, clangd 14.0.6, extension xaver.clang-format 1.9.0, and extension llvm-vs-code-extensions.vscode-clangd 0.1.33, for mostly ...
-1
votes
1
answer
219
views
How to use Allman brace style in Xcode?
I've started to use Xcode instead of CLion(it's paid) for c++ programming recently, but I'm very uncomfortable with the default K&D brace style.
I can't find a way to configure reformatting the ...
3
votes
1
answer
138
views
Example of clang-format getting qualifier placement wrong
Clang-format says about QualifierAlignment:
Warning
Setting QualifierAlignment to something other than Leave, COULD lead to incorrect code formatting due to incorrect decisions made due to clang-...
1
vote
1
answer
76
views
How to store pointer alignment format in a project specific file?
In Visual Studio, I have a project which uses a different pointer alignment for code reformatting than we normally have.
I can configure the pointer alignment in Tools/Options and then at Text Editor/...
1
vote
0
answers
69
views
Array items not staying in newline when passed to a function on formatting
I'm using the vscode extension C/C++ and in the extension setting I've set Clang_format_style as:
{
BasedOnStyle: Google,
SortIncludes: false,
IndentWidth: 4,
MaxEmptyLinesToKeep: 3,
...
0
votes
1
answer
72
views
SortIncludes to honor groups?
My .clang-format file has followings:
IncludeBlocks: Regroup
SortIncludes: CaseInsensitive
I do want to sort the includes, but I don't want includes for standard or 3rd-party headers (#include <&...
0
votes
1
answer
554
views
How to keep clang-format include header at the top of the file?
I'm running into an issue with clang-format setup in my project.
As all my includes are in angled brackets <> I've got and issue with IncludeIsMainRegex.
I want to keep something like this:
For ...
2
votes
2
answers
83
views
Line break after each preprocessor condition with clang-format
I would like to have clang-format insert a line break after each preprocessor condition after the operators.
For example:
#if ((CONDITION_A_SWITCH == ENABLED) || (CONDITION_A_SWITCH == ENABLED) || (...
0
votes
0
answers
16
views
`clang-format` Position of comments on closing braces
I have a code with a lot of nested blocks. They all end together, and for reference, each } has its own comment:
} // end of switch(var)
} // loop over cond2
} // end if for cond1
The ...
0
votes
0
answers
96
views
Clang-Format SpacesInParensOptions: ExceptDoubleParentheses is invalid argument
The Clang-Format documentation says that starting from version 17.0 the following is available:
# Example of usage:
SpacesInParens: Custom
SpacesInParensOptions:
ExceptDoubleParentheses: false
...
1
vote
0
answers
138
views
How to configure clang-format for multi-line template parameters?
I'm mostly indenting the multi-line template parameters as below.
// clang-format off
struct Pretty {
std::vector<
std::pair<
size_t,
std::vector<float>
...
1
vote
0
answers
75
views
clang-format leave comma at beginning
We have a very large codebase from various developers. For many arguments that are written on different lines, there's several ways to do it. I want prevent code, in both styles:
foo( arg1 /* ...
0
votes
1
answer
62
views
Broken BraceWrapping in clang-format in presence of an empty macro
I have the following code
enum MyFlag SOME_EMPTY_MACRO( ARG )
{
MyEnumValue = 1 << 1 //!< ...
};
In my clang-format, I have BraceWrapping.AfterEnum: true
This always get transformed to (...
2
votes
1
answer
109
views
Clang format excessive amount of identation
Why does clang-format add excessive indentation or line breaks to function arguments like std::move(widget) in complex lambdas? How can I configure it to keep arguments inline or reduce unnecessary ...
3
votes
0
answers
125
views
Clang-format: prefer declaration alignment over keeping declaration on a single Line
I'm using clang-format to format my C code, and I've hit a behavior I can't figure out how to reconfigure. Take this unformatted example code:
LongTypeName short_function1(int argument1);
void ...
0
votes
0
answers
62
views
Clang format option to "explode" function declarations
I'm looking for a Clang configuration that will convert code A into code B (see below).
My preference is to "explode" functions with 3 or more arguments for personal readability, and I haven'...
0
votes
0
answers
55
views
clang-format: How to limit binpack-ed arguments length of first line
I have the following code:
function(aaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbb, cccc);
^
└─ ColumnLimit
...
0
votes
1
answer
255
views
Can clang-format eliminate whitespace within angle bracket of include statement?
Consider this include statement. Notice the extra space after iostream:
#include <iostream >
msvc will compile this, but gcc does not. So our Windows devs may not see this failure until our ...
0
votes
0
answers
34
views
Clang-format break new line for element in array
For example,
I want my array looks like this
std::vector<std::vector<std::vector<int>>> input = {
{
{1, 3, 5, 7},
{10, 11, 16, 20},
{23, ...
3
votes
1
answer
186
views
clang-format: How to never align with any token from the previous line?
I want to achieve that the length of a variable/function/etc does never influence the indent of the following lines, or at least as rarely as possible. For example, I already have ...
1
vote
0
answers
60
views
clang-format align assignment to nearest tab (no spaces)
I want to get code like this:
typedef struct FooStruct {
\t u_int16_t bar;\t /**< Blah */
\t u_int16_t baz;\t /**< Bleh */
} Foo;
(where I'm using \t to indicate a 4-column wide tab ...
3
votes
1
answer
399
views
Clang-format binpack OnePerLine for return arguments and variables
I have the following code:
return first_long_function_name(argument) ||
second_long_function_name(argument) || third_long_function_name(argument);
I want it to behave like ...
1
vote
1
answer
136
views
Force clang-format to put multi-line arguments on the next line?
If clang-format finds it needs to put arguments on separate lines, I'd rather it put the first argument on the next line, rather than on the current one with subsequent arguments aligning to a random ...
4
votes
1
answer
5k
views
How to customize Clang Format using Neovim
I am using none-ls to configure Clang-Format, version 19.1.0, as an LSP in Neovim, version v0.10.2.
I want to use a .clangformat file to change the formatting rules, but I cannot figure out how to ...
0
votes
1
answer
143
views
Disable source formatting in stm32cube for a small part in a source file
I am trying to make the source formatter in stm32cubeide code editor to skip some parts of my code. Normally it just works fine but in some cases I want to have it differently for readability.
Take ...
0
votes
1
answer
174
views
Use git-clang-format per commit on a branch, but only for some paths
I have a branch that I've been working on with a few commits. Some of these commits have code that should be formatted with clang-format, but not all code should be formatted. The practical solution ...
3
votes
0
answers
204
views
How do I find out the version of clang-format in CLion?
Given the same .clang-format, the clang-format in CLion behaves differently than the one installed in the OS (Debian clang-format version 14.0.6), I suspect CLion is using clang-format of another ...
2
votes
1
answer
169
views
Can my `.clang-format` include another `.clang-format`?
I have a project with some sub-projects, and want clang-format to sort them differently depending on sub-project. Can I have the sub-projects "include" a top-level .clang-format file?
(...