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

In non-qt programs using std::visit, the code model shows an errors when you try to use std::get.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • Qt Creator 4.8.0
    • C/C++/Obj-C++ Support
    • None
    • Kubuntu 18.04; GCC 7.3; CMake 3.10; QtCreator 4.8.0.
    • Linux/Other display system

    Description

      When using the std::get and std::variant functions, if std::visit is called in the same translation unit, the IDE generates many [errors.](https://yadi.sk/i/4xu1gIXdoIT3FQ).

      #include <variant>
      #include <iostream>
      
      using namespace std;
      
      class Foo {
       public:
       int a{1};
       int b{2};
       void set_a(const int new_a) { a = new_a; }
      };
      class Bat {
       int Arr[200]{};
      };
      int main() {
       int a;
       cin >> a;
       std::variant<Foo, Bat> var_1;
       if (a == 0)
       var_1 = Foo();
       else
       var_1 = Bat();
       std::variant<Foo, Bat> var_2;
       std::visit(
       [](auto& arg) {
       },
       var_2);
       std::get<Foo>(var_1).a = 444;
       std::get<Foo>(var_1).set_a(124); // IDE throws an error (this argument to member function 'set_a' fas type 'const Foo', but function is not marked const)
       cout << std::get<Foo>(var_1).a << endl;
       return 0;
      }
      

      CMake script:

       cmake_minimum_required(VERSION 3.10)
       project(fast_test_2)
       set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
       set(CMAKE_CXX_STANDARD 17)
       add_executable(${PROJECT_NAME} "main.cpp")
      

      Despite this, the code is compiled (GCC 7.3).

       

      I created a thread on the forum [here](https://forum.qt.io/topic/97947/qt-creator-cmake-and-c-17-code-model) and I was advised to write a bug report.

       

      Attachments

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

        Activity

          People

            kosjar Nikolai Kosjar
            mrfieldy Andrey Kuznetsov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes