'std::string' 和'const char[2]'类型不兼容



我正在使用以下编译器:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

我正在运行这个版本的MacOS:

10.15.4

我正在使用此版本的CLion:

CLion 2020.1.1
Build #CL-201.7223.86, built on April 29, 2020
Runtime version: 11.0.6+8-b765.40 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.4
GC: ParNew, ConcurrentMarkSweep
Memory: 1987M
Cores: 6
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins: com.intellij.clion-swift, org.toml.lang, org.rust.lang

这是CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.15)
project(clion_error)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-Wall -Wextra -pedantic -Werror -pedantic-errors -Wshadow -Wstrict-aliasing)
add_executable("clion_error" main.cpp)

这里是main.cpp:

#include <string>
int main(int, char**)
{
std::string my_string = "hello";
return 0;
}

以下是如何再现错误:

  1. 单击顶部菜单中的Code
  2. 单击Inspect Code...
  3. 单击OK

这是我得到的错误:

Types 'std::string' and 'const char[6]' are not compatible

为什么报告此错误?

这确实是CLion 2020.1的回归。仅当通过Code | Inspect Code运行代码分析或禁用clangd服务器时才会出现此问题。

最新更新