clang-format

In clang-format, what do the penalties do?

浪子不回头ぞ 提交于 2020-06-24 05:31:51
问题 The clang-format sytle options documentation includes a number of options called PenaltyXXX. The documentation doesn't explain how these penalties should be used. Can you describe how to use these penalty values and what effect they achieve (perhaps with an example)? 回答1: When you have a line that's over the line length limit, clang-format will need to insert one or more breaks somewhere . You can think of penalties as a way of discouraging certain line-breaking behavior. For instance, say

In clang-format, what do the penalties do?

北战南征 提交于 2020-06-24 05:31:28
问题 The clang-format sytle options documentation includes a number of options called PenaltyXXX. The documentation doesn't explain how these penalties should be used. Can you describe how to use these penalty values and what effect they achieve (perhaps with an example)? 回答1: When you have a line that's over the line length limit, clang-format will need to insert one or more breaks somewhere . You can think of penalties as a way of discouraging certain line-breaking behavior. For instance, say

How can i configure clang format without .clang-format file in every workspace?

本小妞迷上赌 提交于 2020-05-23 08:41:45
问题 I want to configure clang-format without having to copy my .clang-format file to every new workspace. In my settings.json I currently have "C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, IndentCaseLabels: false, TabWidth: 4, UseTab: ForIndentation, ColumnLimit: 0}", "C_Cpp.clang_format_fallbackStyle": "Google" The description for C_Cpp.clang_format_style says Coding style, currently supports: Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit. Use "file" to load the

How can i configure clang format without .clang-format file in every workspace?

筅森魡賤 提交于 2020-05-23 08:41:07
问题 I want to configure clang-format without having to copy my .clang-format file to every new workspace. In my settings.json I currently have "C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, IndentCaseLabels: false, TabWidth: 4, UseTab: ForIndentation, ColumnLimit: 0}", "C_Cpp.clang_format_fallbackStyle": "Google" The description for C_Cpp.clang_format_style says Coding style, currently supports: Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit. Use "file" to load the

Clang-format style rules for parentheses and access modifier

匆匆过客 提交于 2020-04-07 18:57:36
问题 I trying to write my own clang-format style file. There are two aspects I cannot get them right. How do I let it keep an empty line after public: , private: , protected: ? For example, I would like to have public : ctor () {} Instead of public : ctor () {} The second issues is that is there a way to make it insert a space before parentheses when it is following and control statement and function definition. But no space before a function call. For example, I would want, void func () {} func()

clang-format automatically changes function block comments, how to disable it?

耗尽温柔 提交于 2020-03-23 08:06:52
问题 When I select ColumnLimit any non-zero value. It converts block comments into Doxygen block comments (it adds space before * on a new line). But I do not want to change it. How can I disable it? My .clang-format file ColumnLimit: 100 IndentWidth: 4 TabWidth: 4 UseTab: Never It converts the following block comments /***************************************************************************** * A brief comments. * * @param theory . * ************************************************************

Can clang-format force bracing on all control statement bodies?

泄露秘密 提交于 2020-03-22 09:43:58
问题 IE, this: if (x > 5) return test; Would always become: if (x > 5) { return test; } I'm not talking about the brace style (Allman, GNU, Whiteman, etc) I just mean having the braces there at all. There is something to prevent/enable single-line control statements like: if (x > 5) return test; which is AllowShortBlocksOnASingleLine , but that's not what I'm looking for here. If it works on clang 7 that's ideal, but if not let me know. 回答1: It's understandable you would want to stick with clang

Can clang-format force bracing on all control statement bodies?

荒凉一梦 提交于 2020-03-22 09:42:10
问题 IE, this: if (x > 5) return test; Would always become: if (x > 5) { return test; } I'm not talking about the brace style (Allman, GNU, Whiteman, etc) I just mean having the braces there at all. There is something to prevent/enable single-line control statements like: if (x > 5) return test; which is AllowShortBlocksOnASingleLine , but that's not what I'm looking for here. If it works on clang 7 that's ideal, but if not let me know. 回答1: It's understandable you would want to stick with clang

Unify output with different clang-format versions

蹲街弑〆低调 提交于 2020-01-16 00:43:23
问题 We've tried to beautify our code a bit with clang-format tool. In order to get unified result on all machines we've done clang-format --style=llvm --dump-config , which has been tuned a bit and stored into repo. The issue is that clang 10 and 9 seem to provide us with different output for exactly the same code. I've seen changes in comments alignment only so far, but it still breaks the whole idea of getting code style consistent. Another issue is that clang 9 is unable to parse some settings

clang-format removes new lines in array definition with designators

我只是一个虾纸丫 提交于 2020-01-11 10:19:31
问题 I like to define my array values with a designator, when possible: enum Mode { NONE, SPLIT_FILES, SINGLE_FILE, INVALID }; const std::string ModeName[] = { [NONE] = "NONE", [SPLIT_FILES] = "SPLIT_FILES", [SINGLE_FILE] = "SINGLE_FILE", [INVALID] = "INVALID" }; Running this through clang-format (3.5) mangles the new lines and makes it less readable: enum RecorderMode { REC_NONE, REC_SPLIT_FILES, REC_SINGLE_FILE, REC_INVALID }; const std::string RecorderModeName[] = {[REC_NONE] = "NONE", [REC