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

Variable named `template` interpreted as a template declaration in C

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • Qt Creator 4.5.1
    • C/C++/Obj-C++ Support
    • None

    Description

      Take this simple C code:

      void
      write_temp_file()
      {
        char *template;
        template = g_build_filename("/tmp", "test-XXXXXX", 0);
        for (int i = 0; i < 30; i++) {
        }
      }
      
      void
      main()
      {
        foo();
        bar();
        baz();
      }
      

      Select bar() and press Ctrl+Shift+Up. This happens: 

      void
      write_temp_file()
      {
        char *template;
        template = g_build_filename("/tmp", "test-XXXXXX", 0);
        for (int i = 0; i < 30; i++) {
        }
      }
      
      void
      main()
      {
                            bar();
        foo();
        baz();
      }
      

      Note bar() got aligned with the < operator in the for loop. It looks like QtCreator thought that was a template declaration. Indeed `template` is a reserved word in C++, but that is not the case in C.

       

       

      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
              ntrrgc ntrrgc
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes