Search code examples
c++kdevelop

KDevelop semantic analyser getting crazy with std::variant. How to deal with it?


While using KDevelop, I reached some code where the Semantic Analyser get crazy: it mostly consider the full header as semantically wrong with ugly red highlighting everywhere.

I simplified to the maximum the code and this is the result:

enter image description here

In case, for testing MyClass.hpp:

#pragma once

#include <memory>
#include <variant>

template <typename Real, typename Index>
using Io = std::variant<Real, Index>;


template <typename Real, typename Index>
struct MyClass
{
    std::shared_ptr<Io<Real, Index>> ioPtr;
};

I can build this code (just add a main function in another file), and thus consider this as valid code.

KDevelop version is the current Debian one: 5.3.1 (not the latest version unfortunately)

Question:

Why is this happening? Is there something that I can do to avoid this? (without changing the code)


Solution

  • In KDevelop, you need to set the parser language version. This is done in Project -> Open configuration -> Language support -> C++ Parser. Then you'll be able to select C++17 as the language version for the parser.