How can I get clang-format to put the parameters of a brace-initialized construction on the same line?

MHebes

I'm running clang-format, with a .clang-format file which only specifies Language: Cpp, on this input (invalid C++, but that's unimportant for this):

const auto SOME_VARIABLE_NAME = {{"key", { {"key2", std::array{ 0, 0, 0, 0, }}, }}};

I get this output:

const auto SOME_VARIABLE_NAME = {{"key",
                                  {
                                      {"key2",
                                       std::array{
                                           0,
                                           0,
                                           0,
                                           0,
                                       }},
                                  }}};

I would something closer to the following output:

const auto SOME_VARIABLE_NAME = {{"key",
                                  {
                                      {"key2",
                                       std::array{0, 0, 0, 0}},
                                  }}};

I am not sure why clang-format puts a line break after each 0, around column 50.

What setting should I add to my .clang-format to achieve this?

I've tried a few specifiers that I thought might be relevant, to no avail:

  • AllowAllParametersOfDeclarationOnNextLine: true
  • AllowShortFunctionsOnASingleLine: true
  • BinPackParameters: true
  • BreakBeforeBinaryOperators: false
  • ColumnLimit: 120
  • ConstructorInitializerAllOnOneLineOrOnePerLine: true
  • Cpp11BracedListStyle: false
  • IndentFunctionDeclarationAfterType: true
  • PenaltyBreakBeforeFirstCallParameter: 1000
  • Standard: Cpp11

Edit: Still have this problem. Added a comment after the first brace to at least force the braces to the left more:

const auto SOME_VARIABLE_NAME = {  //
    {"key",
     {
         {"key2",
          std::array{
              0,
              0,
              0,
              0,
          }},
     }}};
Eric Backus

The issue is with the trailing comma immediately before the closing brace. The trailing comma (which is optional in c++) tells clang-format to put each element on a separate line. I don't know where this convention comes from, and it does not seem to be documented. In your case, it seems to be getting in the way.

If you remove just the comma after the last "0", the default clang-format settings produce this:

const auto SOME_VARIABLE_NAME = {{"key",
                                  {
                                      {"key2", std::array{0, 0, 0, 0}},
                                  }}};

...which is not quite what you were asking for, but is fairly close.

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

phpcs: How can I modify PSR2 to check that the brace is on the same line as the method?

clang-format: brace on new line except for empty blocks

How can I get the information table and image aligned on the same line

How do I get Notepad++ to put a consistent single space between words on the same line

How can I print literal curly-brace characters in a string and also use .format on it?

Separate each entry of brace-enclosed lists with new-line via clang-format

How can I put Date type parameter as a String in GET request? Format "yyyy-MM-dd"

How can I tell clang-format to indent visibility modifiers?

How do I put a print statement on the same line as a return statement?

Regex - How can I get different string in the same line from a log file?

How can I get four icons on the same line in the table header with bootstrap table?

How can I get four icons on the same line in the table header with bootstrap table?

How can I format multiple CSS grids to look the same

How can I check if a variable is not initialized in Swift?

C# - How can I initilalize List<string[]> in the same line

Gratient Module how can i print text in the same line

How can I align a Material icon & header text on the same line?

How can I change this code so it prints on the same line?

How can I filter django queryset again to get unique parameters?

How can I show GET parameters as a new directory?

How can i get the RGB value of specific straight line in the image?

How can I get all the points on a line in OpenCvSharp?

How can Swagger show both put and get versions of the same Azure function?

How do I get this message box to properly put each sentence on their own line with C#?

How can I print 2 lines if the second line contains the same match as the first line?

How can I get all the strings that have the same pattern

How can i get the same number value as given in JavaScript?

Is there a way to configure clang-format to keep nested namespace declarations on the same line?

How can I convert time in string into a datetime format so that I can get difference between two columns

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  3. 3

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  4. 4

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  5. 5

    Gerenciar recurso shake de Windows Aero com barra de título personalizado

  6. 6

    Como obter dados API adequados para o aplicativo angular?

  7. 7

    UITextView não está exibindo texto longo

  8. 8

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  9. 9

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  10. 10

    Usando o plug-in Platform.js do Google

  11. 11

    Como posso modificar esse algoritmo de linha de visada para aceitar raios que passam pelos cantos?

  12. 12

    Dependência circular de diálogo personalizado

  13. 13

    Coloque uma caixa de texto HTML em uma imagem em uma posição fixa para site para desktop e celular

  14. 14

    iOS: como adicionar sombra projetada e sombra de traço no UIView?

  15. 15

    Como usar a caixa de diálogo de seleção de nomes com VBA para enviar e-mail para mais de um destinatário?

  16. 16

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  17. 17

    How to create dynamic navigation menu select from database using Codeigniter?

  18. 18

    Converter valores de linha SQL em colunas

  19. 19

    ChartJS, várias linhas no rótulo do gráfico de barras

  20. 20

    用@StyleableRes注释的getStyledAttributes。禁止警告

  21. 21

    não é possível adicionar dependência para com.google.android.gms.tasks.OnSuccessListener

quentelabel

Arquivo