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

    • Linux/X11
    • c49ec17d0 (14.0)

    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. formatting-bug.mp4
          962 kB
        2. ClangFormatSettings.png
          ClangFormatSettings.png
          114 kB
        3. clang-format-bug.zip
          0.5 kB

        Issue Links

          For Gerrit Dashboard: QTCREATORBUG-30087
          # Subject Branch Project Status CR V

          Activity

            People

              artem.sokolovskii Artem Sokolovskii (Inactive)
              dilshodm Dilshod Mukhtarov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes