Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-30087

Autoformat using ClangFormat is not working consistently if there is issues in .clang-format file (such as double entry of some variable)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Qt Creator 12.0.1
    • None
    • Linux/X11

    Description

      I enabled "Format while typing" and have my .clang-format file. In older version of QtCreator it was following .clang-format while typing or indenting. Since some version of QtCreator it started to falling back to Qt built-in style while typing and follows .clang-format only if I explicitly use "Format At Cursor" by ClangFormat.

      After some research I found out that my .clang-format contained some entry twice, which makes it "problematic" I suppose.

      In the current version there are two scenarios, which can be seen in the attached videorecording:

      1) .clang-format is correct (no double entry) and typing semicolon inside "else { }" automatically formats by .clang-format rules:

      if (true) {
          ;
      }
      else {
          ;
      } 

      2) .clang-format has double entry of "AllowShortFunctionsOnASingleLine" and typing semicolon inside "else { }" falls back to Qt built-in rules:

      if (true) {
          ;
      } else {
          ;
      } 

      However, if I select that lines and use "Format At Cursor" by ClangFormat it formats correctly as in 1).

       

      I expect that it should not fallback silently to default style, but rather inform user that .clang-format has problems or continue to use .clang-format as in the old versions of QtCreator.

       

      Attachments

        1. clang-format-bug.zip
          0.5 kB
        2. ClangFormatSettings.png
          ClangFormatSettings.png
          114 kB
        3. formatting-bug.mp4
          962 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            artem.sokolovskii Artem Sokolovskii
            dilshodm Dilshod Mukhtarov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes