vscode-cpptools
vscode-cpptools copied to clipboard
Inaccurate messages raised by IntelliSense with Boost Geometry and SFML present
Environment
- OS and Version: Windows 10
- VS Code Version: 1.69.2
- C/C++ Extension Version: 1.11.4
- Other extensions you installed (and if the issue persists after disabling them): clangd (disabled), C/C++ Extension Pack, C/C++ Themes, Better C++ Syntax, Prettier, Intellicode
- If using SSH remote, specify OS of remote machine:
- A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc). Single-project workspace, just one directory with 5 C++ files. IntelliSense keeps red-underlining certain boost namespaces, classes, etc. as well as marking some as error-types, even though all of the code functions properly. The
includePathin c_cpp_properties.json is correct and exactly matches the paths used for includes for the cpp compilation
Bug Summary and Steps to Reproduce
Bug Summary: IntelliSense seems to get very confused on various types in the boost library (specifically boost geometry) and also sometimes reports inaccurate type descriptions when custom structs or other libraries, such as SFML, coexist with boost.
- For example,
modelis not recognized as a subspace ofboost::geometry(call itbg), and this leads tobg::model::point<double, 2, bg::cs::cartesian>to be considered as an<error-type>causing any instances ofpointto be considered undefined. This further invalidatesboxin a similar manner. distanceis also not recognized as a function in thebgnamespace.- Classes/functions
rtree,quadratic,intersects,satisfies, etc. are not recognized in thebg::indexnamespace and thus make my rtree instances undefined. - I have a custom struct called
Node, but IntelliSense thinks that it falls under theboostnamespace i.e. each instance ofNodeis actually an instance ofboost::Node, which is not a real thing - I am using the library SFML for graphics, and a similar issue to
Nodeexists (boost::sf, or sometimes it's evenstd::sf???) Also some errors necessarily related toboostbut are still bugs nonetheless: - I define
using NodeRef = std::reference_wrapper<Node>;, but everywhere in the code IntelliSense thinks it's undefined.
Steps to reproduce:
- Create new cpp file
- Copy paste given code below as well as c_cpp_properties.json
- See error
Expected behavior
I don't expect any of these errors/bugs/inaccuracies to be showing up, as the code compiles successfully and performs as I expect it to.
Code sample and Logs
boosttest.cpp
Relevant snippets from cpp file:
#include <algorithm>
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <random>
#include <chrono>
#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#define cout std::cout
#define endl std::endl
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
struct Node
{
Node *parent = nullptr;
point pos = {};
int id = -1;
};
struct Result
{
int numNodes;
int iter;
int pathNodes;
double pathDistance;
double time;
};
typedef std::pair<box, unsigned int> boxval;
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(Node, double, bg::cs::cartesian, pos.get<0>, pos.get<1>, pos.set<0>, pos.set<1>);
using NodeRef = std::reference_wrapper<Node>;
struct NodeIndexable
{
using value_type = NodeRef;
using result_type = Node &;
result_type operator()(NodeRef r) const { return r; }
};
int main() {
sf::RenderTexture renderTexture;
renderTexture.create(200, 200);
renderTexture.clear();
point start(0, 0), end(200, 200);
bgi::rtree<NodeRef, bgi::quadratic<16>, NodeIndexable> pts;
bgi::rtree<boxval, bgi::quadratic<16>> boxes;
// some of the stuff here is confidential, but the errors are described above, and every example of each type of issue that I've described above has an error (so viewer can try them out and see)
return 0;
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"D:\\Program Files\\boost\\include\\boost-1_79",
"D:\\Program Files\\SFML-2.5.1\\include",
"C:\\Python310\\include",
"C:\\Python310\\Lib\\site-packages\\numpy\\core\\include",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
Log Diagnostics
-------- Diagnostics - 7/28/2022, 12:14:16 AM
Version: 1.11.4
Current Configuration:
{
"name": "Win32",
"includePath": [
"D:\\Program Files\\boost\\include\\boost-1_79",
"D:\\Program Files\\SFML-2.5.1\\include",
"C:\\Python310\\include",
"C:\\Python310\\Lib\\site-packages\\numpy\\core\\include",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"mergeConfigurations": false,
"browse": {
"path": [
"D:\\Program Files\\boost\\include\\boost-1_79",
"D:\\Program Files\\SFML-2.5.1\\include",
"C:\\Python310\\include",
"C:\\Python310\\Lib\\site-packages\\numpy\\core\\include",
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ D:\Documents\Coding\bproj\boosttest.cpp ]:
D:\Documents\Coding\bproj\boosttest.cpp
Translation Unit Configurations:
[ D:\Documents\Coding\bproj\boosttest.cpp ]:
Process ID: 8172
Memory Usage: 630 MB
Compiler Path: D:\Program Files\mingw64\bin\g++.exe
Includes:
D:\PROGRAM FILES\BOOST\INCLUDE\BOOST-1_79
D:\PROGRAM FILES\SFML-2.5.1\INCLUDE
C:\PYTHON310\INCLUDE
C:\PYTHON310\LIB\SITE-PACKAGES\NUMPY\CORE\INCLUDE
D:\DOCUMENTS\CODING\RICE
D:\PROGRAM FILES\MINGW64\LIB\GCC\X86_64-W64-MINGW32\8.1.0\INCLUDE\C++
D:\PROGRAM FILES\MINGW64\LIB\GCC\X86_64-W64-MINGW32\8.1.0\INCLUDE\C++\X86_64-W64-MINGW32
D:\PROGRAM FILES\MINGW64\LIB\GCC\X86_64-W64-MINGW32\8.1.0\INCLUDE\C++\BACKWARD
D:\PROGRAM FILES\MINGW64\LIB\GCC\X86_64-W64-MINGW32\8.1.0\INCLUDE
D:\PROGRAM FILES\MINGW64\LIB\GCC\X86_64-W64-MINGW32\8.1.0\INCLUDE-FIXED
D:\PROGRAM FILES\MINGW64\X86_64-W64-MINGW32\INCLUDE
Defines:
_DEBUG
UNICODE
_UNICODE
Standard Version: c++14
IntelliSense Mode: windows-gcc-x64
Other Flags:
--g++
--gnu_version=80100
Total Memory Usage: 1867 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 17784
Number of files parsed: 2826
Screenshots
model not recognized

point not defined

box not defined

NodeRef not defined

Same block of code with SFML RenderTexture

rtree, quadratic not members of boost::geometry::index

We repro the issue. It repros with mingw/gcc but not with msvc/cl.exe. I'm looking into the root cause of the parser error...
This error is a cascading parse failure caused by our lack of support for __float128 on Windows: https://github.com/microsoft/vscode-cpptools/issues/9558 . The error doesn't occur if you avoid headers that have a dependency on the __float128 type, which may be difficult to do, i.e. if you can somehow force BOOST_MATH_USE_FLOAT128 to always be undefined.
Another potential workaround is to move the headers you need before the headers that have a dependency on the __float128 type, because that missing dependency causes types defined afterwards to fail to compile. That may also be hard to do to the complicated include dependencies of the boost/geometry headers.
Also, the error doesn't repro on Linux, so another potential workaround is to use WSL instead of mingw.
Closing as duplicate.