Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 spans and range algorithms give erroneous Intellisense errors #10024

Closed
0xjc opened this issue Oct 17, 2022 · 16 comments
Closed

C++20 spans and range algorithms give erroneous Intellisense errors #10024

0xjc opened this issue Oct 17, 2022 · 16 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@0xjc
Copy link

0xjc commented Oct 17, 2022

Environment

  • OS and Version: Ubuntu 20.04.5 LTS
  • VS Code Version: 1.73.0-insider
  • C/C++ Extension Version: v1.13.2

When using gcc-10 in C++20 mode, Intellisense will often give errors on conversions of contiguous ranges to std::span, and also when using most algorithms under std::ranges. This code compiles and works properly under g++-10 -std=c++20.

Bug Summary and Steps to Reproduce

See code

Expected behavior

No response

Code sample and Logs

Code sample:

#include <algorithm>
#include <iostream>
#include <ranges>
#include <span>
#include <vector>

void f_0(std::span<const int> x) { std::cout << x.size() << "\n"; }

void f(const std::vector<int>& x) { f_0(x); }
//                                      ^
// no suitable user-defined conversion from "const std::vector<int,
// std::allocator<int>>" to "std::span<const int, 18446744073709551615UL>"
// exists C/C++(312)

void g(const std::vector<int>& x) { std::cout << std::ranges::max(x) << "\n"; }
//                                               ^^^
// no instance of overloaded function "std::ranges::__max_fn::operator()"
// matches the argument list C/C++(304)
// argument types are: (const std::vector<int, std::allocator<int>>)
// object type is: const std::ranges::__max_fn

int main() {
  auto x = std::vector{3, 4, 5};
  f(x);
  g(x);
}

c_cpp_properties.json:

{
  "configurations": [
      {
          "name": "Linux",
          "intelliSenseMode": "gcc-x64",
          "cppStandard": "c++20",
          "compilerPath": "/usr/bin/gcc-10"
      }
  ],
  "version": 4
}

Diagnostics:

-------- Diagnostics - 10/17/2022, 1:35:18 PM
Version: 1.13.2
Current Configuration:
{
    "name": "Linux",
    "intelliSenseMode": "gcc-x64",
    "cppStandard": "c++20",
    "compilerPath": "/usr/bin/gcc-10",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
...
Translation Unit Configurations:
[ /home/jcai/test/test.cpp ]:
    Process ID: 1264701
    Memory Usage: 770 MB
    Compiler Path: /usr/bin/gcc-10
    Includes:
        /usr/include/c++/10
        /usr/include/x86_64-linux-gnu/c++/10
        /usr/include/c++/10/backward
        /usr/lib/gcc/x86_64-linux-gnu/10/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++20
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=100300

Screenshots

No response

Additional context

No response

@hwmaier
Copy link

hwmaier commented Oct 18, 2022

Experiencing similar issue. Despite configuring "cppStandard": "c++20" in c_cpp_properties.json, the parser flags namespace "std" has no member "span" errors. Code compiles w/o warning with MSVC.

@Colengms Colengms assigned Colengms and unassigned Colengms Oct 20, 2022
@Colengms
Copy link
Collaborator

Hi @0xjc . I'm able to reproduce the issue. I've opened an internal issue (1656876) against the IntelliSense library. We share the IntelliSense implementation with VS.

@Colengms Colengms added Language Service Visual Studio Inherited from Visual Studio bug labels Oct 26, 2022
@Colengms Colengms added this to the Tracking milestone Oct 26, 2022
@Grant12311
Copy link

Hi! I'm having a similar issue. I get this error when using std::ranges::any_of and similar messages with other ranges stuff. The code compiles just fine with GCC 11 though.

no instance of overloaded function "std::ranges::__all_of_fn::operator()" matches the argument list

@marxin
Copy link

marxin commented Jan 25, 2023

I face the same issue, is there any progress on the internal issue you opened @Colengms?

@Grant12311
Copy link

Yeah last I checked this issue is still ongoing so an update would be appreciated.

@mwhds97
Copy link

mwhds97 commented Feb 6, 2023

I have the same issue, with GCC 12

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Feb 6, 2023

No progress has been made yet, but I've pinged the team and mentioned the 9 or so upvotes or user comments.

UPDATE: The bug has been fixed (for 1.15.0), but we still have to merge in the fix and test it out.

@davidBronicki
Copy link

Also having this issue. Probably related: intellisense believes ranges::range<vector<double>> evaluates to false. I've tried this with clang 15 and 17.

@Jesseeee
Copy link

Jesseeee commented Mar 3, 2023

Having the same issue with gcc 12.2 trying to use any std::ranges functions, gives such errors
"message": "no instance of overloaded function "std::ranges::__find_fn::operator()" matches the argument list",
"message": "argument types are: (std::vector<SessionId, std::allocator>, const SessionId)",
"message": "object type is: const std::ranges::__find_fn",

@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.15.0 Mar 3, 2023
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 8, 2023
@sean-mcmanus
Copy link
Collaborator

The fix is available with 1.15.0 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.0

If you're still hitting an incorrect IntelliSense error with ranges, you're probably hitting a different root cause bug, such as #9953 and #8039, or let us know the details in a new issue if you believe it's a different root cause.

@marxin
Copy link

marxin commented Mar 17, 2023

I can confirm it works for me with the update extension and my test-case (mold linker)! Thank you for the fix.

@janderudder
Copy link

Is this fixed in vs code ? I use it on Windows and it auto updates regularly but Intellisense still reports an error when converting from std::vector using std::span constructor.

@sean-mcmanus
Copy link
Collaborator

@janderudder It's fixed with 1.15.1 (pre-release), but there are other span/range-related bugs that are not fixed yet which we have other issues tracking, so you could be hitting those or you could file a new issue with more repro details.

@janderudder
Copy link

janderudder commented Apr 5, 2023

Thank you @sean-mcmanus. I think I'm in the most basic situation of getting, for instance, no suitable user-defined conversion from "const std::vector<std::string, std::allocator<std::string>>" to "std::span<const std::string, 18446744073709551615UL>" exists [C/C++(312)] when simply using a std::vector where a std::span is expected, or constructing a span by assigning a vector (which of course compiles without issue).

I just noticed that the error goes away when disabling Microsoft's "C/C++ for Visual Studio Code" extension. I have vscode 1.77.0.

Edit: oh but that disables C++ Intellisense entirely it seems. I thought it retained most of its features without this extension. My bad.

@sean-mcmanus
Copy link
Collaborator

@janderudder Can you file a new bug report on that with a code sample and info like the compiler/OS used? I'm not sure if that particular case tracked by an existing issue or not.

@sean-mcmanus
Copy link
Collaborator

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.4, and more range fixes are going to be in 1.16.0 (#8039).

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

10 participants