KDevelop 语义分析器对 std::variant 变得疯狂如何处理?

问题描述

在使用 KDevelop 时,我遇到了一些让语义分析器发疯的代码:它主要认为完整的标题在语义上是错误的,到处都是丑陋的红色突出显示。

我最大限度地简化了代码,结果如下:

enter image description here

如果要测试 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;
};

我可以构建此代码(只需在另一个文件中添加一个 main 函数),从而将其视为有效代码。

KDevelop 版本是当前的 Debian 版本:5.3.1(不幸的是不是最新版本)

问题:

为什么会这样? 我可以做些什么来避免这种情况? (无需更改代码)

解决方法

在KDevelop中,需要设置解析器语言版本。这是在 Project -> Open configuration -> Language support -> C++ Parser 中完成的。然后您就可以选择 C++17 作为解析器的语言版本。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...