Qt creator, CMake and c++17 code model.



  • Hi, everybody. I write code in qt-creator 4.8.0 + cmake (on linux). When using the std::get and std::variant functions, if std::visit is called in the same translation unit, the IDE generates many errors.

    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 have a section of code where std::get is actively used, and after adding a call to std::visit, qt-creator has colored the 2к code lines in red. How can I fix this?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You may have unearthed a shortcoming from Qt Creator's current code model. You should check the bug report system to see if it's something known.



  • @SGaist I didn't find my issue there. Should I write a bug report?


  • Lifetime Qt Champion

    One thing you can do is test the Qt Creator 4.9 Beta. If you still have the issue with it, then yes, please open a report.


  • Qt Champions 2018

    That's QTCREATORBUG-21873 now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.