vscode-cpptools
vscode-cpptools copied to clipboard
Catch2 IntelliSense Warning Squiggles REQUIRE macro
Environment
- OS and Version:
- VS Code Version:
- C/C++ Extension Version:
- If using SSH remote, specify OS of remote machine:
Bug Summary and Steps to Reproduce
Bug Summary:
// // t2.cpp //
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_approx.hpp>
TEST_CASE("Foobar", "[baz]") {
SECTION("WTF is going on here") {
REQUIRE(2 + 2 == 4);
bool ok = true;
REQUIRE(ok);
}
}
Why is REQUIRE(2 + 2 = 4); OK?
and
REQUIRE(ok); is marked with a warning (red squiggle)
Beyond bizarre!!
Configuration and Logs
I am running on a MacBook Pro (Apple M1 Pro), 14" 2021.
OS: Ventura 13.6.2
C++: C++20, clang++
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin22.6.0
Thread model: posix
Catch2 v 3.5.2
% brew info catch2
==> catch2: stable 3.5.2 (bottled)
Modern, C++-native, header-only, test framework [actually, it's no longer header only as of v3.x]
https://github.com/catchorg/Catch2
c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src",
//"${workspaceFolder}/src/common",
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
Other Extensions
No response
Additional context
No response
-------- Diagnostics - 2/19/2024, 7:15:43 PM
Version: 1.18.5
Current Configuration:
{
"name": "Mac",
"includePath": [
"/Users/david/Ezm/interpreter/**",
"/Users/david/Ezm/interpreter/src"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"compileCommands": "/Users/david/Ezm/interpreter/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "macos-clang-arm64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerPathInCppPropertiesJson": "/usr/bin/clang++",
"compileCommandsInCppPropertiesJson": "${workspaceFolder}/build/compile_commands.json",
"mergeConfigurations": false,
"browse": {
"path": [
"/Users/david/Ezm/interpreter/**",
"/Users/david/Ezm/interpreter/src",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
cpptools version (native): 1.18.3.0
Translation Unit Mappings:
[ /Users/david/Ezm/interpreter/tests/t2.cpp ]:
/Users/david/Ezm/interpreter/tests/t2.cpp
[ /Users/david/Ezm/interpreter/tests/t1.cpp ]:
/Users/david/Ezm/interpreter/tests/t1.cpp
Translation Unit Configurations:
[ /Users/david/Ezm/interpreter/tests/t2.cpp ]:
Process ID: 14993
Memory Usage: 7 MB
Compiler Path: /usr/bin/clang++
Includes:
/Users/david/Ezm/interpreter/build/tests/test_ezm_interpreter.p
/Users/david/Ezm/interpreter/build/tests
/Users/david/Ezm/interpreter/tests
/Users/david/Ezm/interpreter/build/src
/Users/david/Ezm/interpreter/src
/opt/homebrew/Cellar/spdlog/1.12.0/include
/opt/homebrew/Cellar/fmt/10.2.1/include
/opt/homebrew/Cellar/catch2/3.5.2/include
/opt/homebrew/include
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
Frameworks:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
Defines:
SPDLOG_SHARED_LIB
SPDLOG_COMPILED_LIB
SPDLOG_FMT_EXTERNAL
Standard Version: c++20
IntelliSense Mode: macos-clang-arm64
Other Flags:
--clang
--clang_version=160000
compile_commands.json entry:
directory: /Users/david/Ezm/interpreter/build
file: ../tests/t2.cpp
command: c++ -Itests/test_ezm_interpreter.p -Itests -I../tests -Isrc -I../src -I/opt/homebrew/Cellar/spdlog/1.12.0/include -I/opt/homebrew/Cellar/fmt/10.2.1/include -I/opt/homebrew/Cellar/catch2/3.5.2/include -I/opt/homebrew/include -fdiagnostics-color=always -Wall -Winvalid-pch -std=c++20 -O0 -g -stdlib=libc++ -DSPDLOG_SHARED_LIB -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -MD -MQ tests/test_ezm_interpreter.p/t2.cpp.o -MF tests/test_ezm_interpreter.p/t2.cpp.o.d -o tests/test_ezm_interpreter.p/t2.cpp.o -c ../tests/t2.cpp
output: tests/test_ezm_interpreter.p/t2.cpp.o
[ /Users/david/Ezm/interpreter/tests/t1.cpp ]:
Process ID: 15008
Memory Usage: 7 MB
Compiler Path: /usr/bin/clang++
Includes:
/Users/david/Ezm/interpreter/build/tests/test_ezm_interpreter.p
/Users/david/Ezm/interpreter/build/tests
/Users/david/Ezm/interpreter/tests
/Users/david/Ezm/interpreter/build/src
/Users/david/Ezm/interpreter/src
/opt/homebrew/Cellar/spdlog/1.12.0/include
/opt/homebrew/Cellar/fmt/10.2.1/include
/opt/homebrew/Cellar/catch2/3.5.2/include
/opt/homebrew/include
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
Frameworks:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
Defines:
SPDLOG_SHARED_LIB
SPDLOG_COMPILED_LIB
SPDLOG_FMT_EXTERNAL
Standard Version: c++20
IntelliSense Mode: macos-clang-arm64
Other Flags:
--clang
--clang_version=160000
compile_commands.json entry:
directory: /Users/david/Ezm/interpreter/build
file: ../tests/t1.cpp
command: c++ -Itests/test_ezm_interpreter.p -Itests -I../tests -Isrc -I../src -I/opt/homebrew/Cellar/spdlog/1.12.0/include -I/opt/homebrew/Cellar/fmt/10.2.1/include -I/opt/homebrew/Cellar/catch2/3.5.2/include -I/opt/homebrew/include -fdiagnostics-color=always -Wall -Winvalid-pch -std=c++20 -O0 -g -stdlib=libc++ -DSPDLOG_SHARED_LIB -DSPDLOG_COMPILED_LIB -DSPDLOG_FMT_EXTERNAL -MD -MQ tests/test_ezm_interpreter.p/t1.cpp.o -MF tests/test_ezm_interpreter.p/t1.cpp.o.d -o tests/test_ezm_interpreter.p/t1.cpp.o -c ../tests/t1.cpp
output: tests/test_ezm_interpreter.p/t1.cpp.o
Total Memory Usage: 14 MB
Browse Paths from compile_commands.json, from workspace folder: /Users/david/Ezm/interpreter
/Users/david/Ezm/interpreter/build
/Users/david/Ezm/interpreter/build/../src
/Users/david/Ezm/interpreter/build/../tests
/Users/david/Ezm/interpreter/build/src
/Users/david/Ezm/interpreter/build/src/ezm_interpreter.p
/Users/david/Ezm/interpreter/build/tests
/Users/david/Ezm/interpreter/build/tests/test_ezm_interpreter.p
/opt/homebrew/Cellar/catch2/3.5.2/include
/opt/homebrew/Cellar/fmt/10.2.1/include
/opt/homebrew/Cellar/readline/8.2.7/include
/opt/homebrew/Cellar/spdlog/1.12.0/include
/opt/homebrew/include
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 33313
Hi @david-29 . Does your code compile when built? Since you're using a compile_commands.json file, and an entry was found and used for t1.cpp and t2.cpp (based on your diagnostics log), IntelliSense for the file would be configured based on those command lines.
What was the error message associated with the red squiggle? That could provide some additional context.
Could you set "C_Cpp.loggingLevel": "Debug" and provide the output of the C/C++ output channel leading up to the repro?
Hi @Colengms,
I'm in a broken state at the moment. Should be able to build again tomorrow. I was able to build those tests with meson/ninja when I submitted the bug report. I'll add a little detail below.
I'm thinking that the 'REQUIRE' macro is a beast & that's causing problems for IntelliSense and/or your built in C++ compiler (I'm building with clang++ 15.0 since Apple is way behind updating clang.) I saw a cry out from a Catch2 dev guy recently re their macros.
I don't really care anymore if you guys want to paint squiggles on the Catch2 macros. It's annoying, but harmless since I can build and run (including the tests) anyway.
Here's the additional stuff. I'll update tomorrow once I can build again.
david@Davids-MBP tests % cat t1.cpp
// // t1.cpp //
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_approx.hpp>
#include "interpreter.hpp"
TEST_CASE("Arithmetic expressions are evaluated correctly", "[arithmetic]") { using ezm::xp::VM; using ezm::xp::VmResult;
SECTION("2.0 + 3.0 should return 5.0") {
VM vm;
VmResult result = vm.run("2.0 + 3.0");
REQUIRE(result.ok);
auto value = std::get<double>(result.value);
REQUIRE(value == Catch::Approx(5.0));
}
}
david@Davids-MBP tests % cat t2.cpp
// // t2.cpp //
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_approx.hpp>
TEST_CASE("Foobar", "[baz]") {
SECTION("WTF is going on here") {
REQUIRE(2 + 2 == 4);
// bool ok = true;
// REQUIRE(ok);
}
}
david@Davids-MBP tests %
david@Davids-MBP tests % ls meson.build t1.cpp t2.cpp
david@Davids-MBP tests % cat meson.build
Build setup for testing the EZM interpreter
test_sources = [ 't1.cpp', 't2.cpp', '../src/interpreter.cpp', ]
Include the 'src' header files
src_includes = include_directories( '../src', )
Define test executable
test_ezm_interpreter = executable( 'test_ezm_interpreter', sources : test_sources, include_directories : src_includes, dependencies : [spdlog_dep, fmt_dep, catch2_dep], link_with : [] )
Define test
test('ezm_test_suite', test_ezm_interpreter)
david@Davids-MBP tests %
Finally got back to the point where I could compile my project. The red squiggles are now gone, both on the test which was trivial & independent of my project and on my t1.cpp test which tests some of the functionality in my interpreter.
I don't know if some of the system header file changes I made to my project cleared up the problem. Or whether you guys made some changes to the extension to deal with the problem. I think I have autoload enabled for the VSCode CPP Tools extension.
From my point of view, you may close this issue.
As a footnote, back a few days ago, I was often getting red squiggles at the very top of some of my header and cpp files. When I hovered over the squiggles, the indication was that IntelliSense was unhappy with the code in some of the system header files. But it shouldn't be looking into those files in the first place. That issue also seems to have gone away now. Don't know if it was a related symptom to whatever problem I was having that led me to post my bug report.