我有一个问题,我想是由Microsoft C/C++插件引起的。Intellisense在谷歌测试函数中显示了错误,但没有实际错误(测试编译和运行没有任何问题(。
当我将鼠标悬停在带有这些红色错误曲线的函数上时,它会扩展到功能,F12(转到定义(也能工作。
我该如何摆脱这些"智能";错误";?
我已经尝试搜索错误消息;intellisense Gtest VSCode";类似的,但没有找到任何有用的解决方案。我的猜测是我错过了什么,但是什么?
我也尝试过使用c_cpp_properties.json(试图包括gtest的确切路径,强制包括实际的gtest.h文件等(,但也没有成功。
c_cpp_properties.json
它非常简单,基本上:
"includePath": [
"${workspaceFolder}/**"
],
somefile.h
typedef struct {
unsigned short a;
} myStruct;
somefile.c
myStruct s[5];
unsigned short someFunction(void)
{
// Do stuff
return s[somePosition].a;
}
测试.cpp
#include "gtest/gtest.h"
extern "C" {
#include "somefile.h"
extern myStruct s[];
}
TEST(someTest, firstTest)
{
EXPECT_EQ(s[somePosition].a, someFunction());
}
INSTANTIATE_TEST_CASE_P(someFunction, secondTest,
testing::Values(
some_test{ "hello", 0 },
some_test{ "bye", 1 }
));
VSCode C/C++智能感应输出
firstTest,EXPECT_EQ:错误
expression must have bool type (or be convertible to bool)C/C++(711)
secondTest,INSTANTIATE_TEST_CASE_p:错误
namespace "std" has no member "string"C/C++(135)
通过编辑c_cpp_properties.json:解决
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/Tests/packages/Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1/build/native/include/**"
],