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

Operator[] in initializer list breaks auto-indent, when used to assign variable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3: Somewhat important
    • None
    • Qt Creator 4.2.1, Qt Creator 4.3.0-rc1
    • C/C++/Obj-C++ Support
    • None
    • Qt Creator 4.2.1 Based on Qt 5.8.0 (GCC 6.3.1 20170306, 64 bit) on Linux 4.10.10-1-ARCH

    Description

      void foobar()
      {
      	char foo[2] = {'a', 'b'};
      	char bar = char{foo[0]};/*POS1*/
      /*POS2*/
      
      	//Same goes for already declared variables:
      	bar = char{foo[1]};/*POS1*/
      /*POS2*/
      
      	//Without operator= this does not happen:
      	char bar2{foo[0]};/*POS1*/
      	/*POS2*/
      
      	//Without {}-initializer lists this does not happen as well:
      	bar2 = char(foo[0]);/*POS1*/
      	/*POS2*/
      }
      

      If you insert a linebreak (press Enter) at the marked position (POS1) your cursor will end up in POS2 (without auto-indentation). This happens regardless of codestyle.
      For now, I could only reproduce this by using a operator[] inside a (curly brace) initializer.
      With a line like the fifth in this code snippet, the indentation for the entire scope gets broken.
      Auto formating is affected as well.

      Edit, found something WEIRD:
      For every indentation breaking line in a scope, the auto-indent misses one indentation.
      When the start of the line is reached, the auto-indent works again:

      namespace whatever
      {
      	void foobar2()
      	{
      		char foo[2] = {'a', 'b'};
      		char bar = char{foo[0]};/*POS1*/
      	/*POS2*/
      
      		bar = char{foo[2]};/*POS1*/
      /*POS2*/
      
      		bar = char{foo[2]};/*POS1*/
      		/*POS2*/
      		bar = char{foo[2]};/*POS1*/
      		/*POS2*/
      	}
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              kosjar Nikolai Kosjar
              3ik3 3ik3
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes