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

clangd/clang-tidy give errors but MSVC doesn't

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • Qt Creator 11.0.2
    • None
    • Windows

    Description

      If I compile my cmake-based project from Qt Creator 11.0.2 on Windows using the build tools that come with MS Visual Studio 2022, the project compiles without errors or warnings emitted. However, if I run clang-tidy on the entire project, there are quite a few files that cannot be processed due to compile errors in the file. If I open those files with errors in Creator, I see the red circle in the margin, indicating an error, on the same lines that clang-tidy complains about.
       
      Clearly clangd/clang-tidy and MSVC are doing something different if the compile is successful only in MSVC, but I can't figure out why that would be.
       
      In the QtC global settings for clangd, I have "Build-system warnings" selected for Diagnostic configuration. In the project settings for this project, "Use global settings" is checked for everything, including Clang Tools and clangd. I am using the default clangd and clang-tidy executables that ship with QtC.
       
      I was able to simplify one example of this problem in a way that should be reproducible. Extract the contents of the attached .zip file, which are files from zlib. Open CMakeLists.txt in QtC and build the debug configuration. That should build successfully, though there will be quite a few compiler warnings.
       
      Now, open the file trees.h. If clangd is enabled, it will show an error on line 3: "trees.h:: Unknown type name 'local'". There are also clangd errors later in the file.
       
      Similarly, if you use clang-tidy using the default checks on all of the files in the project, it will fail to analyze 6 of the files:
      crc32.h
      inffast.h
      inffixed.h
      inflate.h
      inftrees.h
      trees.h
       
      In an ideal world, if the project compiles with MSVC, I would expect clangd and clang-tidy to also be able to handle compiling/parsing the file. Otherwise it makes clangd and clang-tidy much less useful since they are not giving an accurate representation of what the actual compile results will be.
       
      We see similar issues with other files in our real application, some of which won't be easy to provide a way to reproduce. If there's a way for me to provide certain information about those errors so you can fix the problem without providing a way to reproduce, please let me know.
       

      Attachments

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

        Activity

          People

            kandeler Christian Kandeler
            aclight Adam Light
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes