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

ClangFormat removes empty lines before statements, flacky indentation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • Qt Creator 4.9.0-beta2
    • Qt Creator 4.9.0-beta1
    • C/C++/Obj-C++ Support
    • None
    • Kubuntu 18.10 x86_64
    • Linux/X11

    Description

      We have a custom logging library in our project. Emitting a log record involves two macros, defined similar to the following:

      #define LOG(lg, lvl) \
      	do\
      	{\
      		logging::logger& __lg = (lg);\
      		if (logging::message __message = __lg.check_filters(logging::level::lvl))\
      		{\
      			logging::formatting_stream __strm = logging::get_formatting_stream();\
      			__strm.stream
      
      #define LOG_END \
      			;\
      			__strm.stream.flush();\
      			__lg.send_message(__message, __strm.result.c_str(), __strm.result.size());\
      		}\
      	}\
      	while (false)
      

      In the code one uses these macros like this:

      LOG(lg, info) << "Hello" LOG_END;
      

      The problem is that with ClangFormat plugin enabled, whenever I type the opening brace after `LOG` or semicolon after `LOG_END` QtCreator removes any empty lines before this logging code.

      This also happens when I type `if`, `while` or `switch` statements and an opening brace - QtCreator removes empty lines before the line I'm typing. Interestingly, the macros above are defined in terms of `do`/`while`, which, when typed manually, does not exhibit this behavior. Instead, it shows a different bug: the `while` line gets indented one level deeper as you type the parenthesis, and then indented back as you type the semicolon. To reproduce, try typing this and watch the indentation of the last line as you type it:

      do
      {
      }
      while ();
      

      This is reproducible with QtCreator 4.9.0 beta2.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              yvvan Ivan Donchevskii
              lastique Andrey Semashev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes