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

Clang Code Model failure with C++20 template lambdas

    XMLWordPrintable

Details

    • Linux/X11

    Description

      The Clang Code Model backend needs continuously restarting when using C++20 template lambdas. Here's a simple example:

      CMakeLists.txt

      cmake_minimum_required(VERSION 3.12)
      
      project(scratch)
      
      add_executable(scratch ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
      
      target_compile_features(scratch PUBLIC cxx_std_20)
      set_target_properties(scratch PROPERTIES CXX_EXTENSIONS OFF)
      
      target_compile_options(scratch PRIVATE
          $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
              -Werror -Wall -Wextra>
          $<$<CXX_COMPILER_ID:MSVC>:
              /W4>
      )
      

      main.cpp:

      #include <boost/mp11/algorithm.hpp>
      
      #include <tuple>
      #include <string>
      
      namespace
      {
      template <typename Tuple, typename F>
      constexpr void tuple_type_iterator(F&& f)
      {
          constexpr auto N = std::tuple_size_v<std::decay_t<Tuple>>;
          boost::mp11::mp_for_each<boost::mp11::mp_iota_c<N>>([&](auto i) {
              f.template operator()<std::tuple_element_t<i, Tuple>>(i);
          });
      }
      }
      
      int main()
      {
          using Tuple = std::tuple<std::string, double, int>;
      
          tuple_type_iterator<Tuple>([]<typename T>(auto i) {
              static_assert(std::is_same_v<std::tuple_element_t<i, Tuple>, T>);
          });
          return 0;
      }
      

      Results in this kind of output in the 'General Messages' Pane:

      2020-12-06T15:00:12 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      2020-12-06T15:00:13 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      2020-12-06T15:01:05 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      2020-12-06T15:01:06 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      2020-12-06T15:01:07 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      2020-12-06T15:01:08 Clang Code Model: Error: The clangbackend process has finished unexpectedly and was restarted.
      

      Switching the code to use a non-template lambda allows it restart and run successfully.

      Attachments

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

        Activity

          People

            kandeler Christian Kandeler
            camden camden
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes