microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Inaccurate messages raised by IntelliSense with Boost Geometry and SFML present #9657

Closed LitMSCTBB closed 2 years ago

LitMSCTBB commented 2 years ago

Environment

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.

Steps to reproduce:

  1. Create new cpp file
  2. Copy paste given code below as well as c_cpp_properties.json
  3. 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 image

point not defined image image image

box not defined image

NodeRef not defined image

Same block of code with SFML RenderTexture image image image

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

sean-mcmanus commented 2 years ago

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...

sean-mcmanus commented 2 years ago

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.

Colengms commented 2 years ago

Closing as duplicate.