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++23 Ranges Pipe Operator Not Recognized by IntelliSense #13125

Open
marpaia opened this issue Jan 7, 2025 · 2 comments
Open

C++23 Ranges Pipe Operator Not Recognized by IntelliSense #13125

marpaia opened this issue Jan 7, 2025 · 2 comments
Assignees
Labels
bug Language Service more info needed The issue report is not actionable in its current state

Comments

@marpaia
Copy link

marpaia commented Jan 7, 2025

Environment

  • VS Code Version: 1.93.1
  • C/C++ Extension Version: v1.22.11
  • OS: macOS
  • Compiler: Clang (Apple)
  • C++ Standard: C++23
  • Standard Library: libc++

Bug Summary and Steps to Reproduce

Bug Summary

IntelliSense incorrectly reports errors for valid C++23 ranges pipe operator syntax in a modern C++ project. The project is a single CMake project using C++23 with libc++ and Clang. The error occurs in any source file that uses the ranges pipe operator, despite the code compiling and running correctly.

Steps to Reproduce

  1. Create a new C++ project using CMake

  2. Configure the project to use C++23 with libc++ and Clang

  3. Add the following configuration to .vscode/c_cpp_properties.json:

    {
        "configurations": [
            {
                "name": "Mac",
                "compilerPath": "/usr/bin/clang++",
                "includePath": [
                    "${workspaceFolder}/**",
                    "${workspaceFolder}/build/**",
                    "/opt/homebrew/include",
                    "/opt/homebrew/opt/libomp/include"
                ],
                "defines": [
                    "_LIBCPP_ENABLE_EXPERIMENTAL",
                    "_LIBCPP_STD_VER=23"
                ],
                "cStandard": "c23",
                "cppStandard": "c++23",
                "intelliSenseMode": "clang-arm64",
                "compilerArgs": [
                    "-fexperimental-library",
                    "-stdlib=libc++",
                    "-std=c++23"
                ]
            }
        ]
    }
  4. Create a new .cpp file with the following code:

    auto longFlag =
        flags | std::views::filter([](std::string_view f) { return f.starts_with("--"); }) | std::views::take(1);

Expected behavior:

  • IntelliSense should recognize the ranges pipe operator as valid C++23 syntax
  • No error squiggles should appear

Actual behavior:

  • IntelliSense shows error: "no operator '|' matches these operands" (error 349)
  • Code compiles and runs correctly with Clang

Error Details

IntelliSense error message:

    no operator "|" matches these operands
    operand types are: std::__1::ranges::drop_while_view<std::__1::basic_string_view<char, std::__1::char_traits<char>>, int (*)(int _c)> | const std::__1::ranges::views::__reverse::__fn

The code compiles and runs correctly with Clang, suggesting this is an IntelliSense limitation with C++23 ranges features.

Configuration and Logs

My c_cpp_properties.json:


    {
        "configurations": [
            {
                "name": "Mac",
                "compilerPath": "/usr/bin/clang++",
                "includePath": [
                    "${workspaceFolder}/**",
                    "${workspaceFolder}/build/**",
                    "/opt/homebrew/include",
                    "/opt/homebrew/opt/libomp/include"
                ],
                "defines": [
                    "_LIBCPP_ENABLE_EXPERIMENTAL",
                    "_LIBCPP_STD_VER=23"
                ],
                "cStandard": "c23",
                "cppStandard": "c++23",
                "intelliSenseMode": "clang-arm64",
                "compilerArgs": [
                    "-fexperimental-library",
                    "-stdlib=libc++",
                    "-std=c++23"
                ]
            }
        ]
    }


C/C++: Log Diagnostics:


-------- Diagnostics - 1/7/2025, 1:51:13 PM
Version: 1.22.11
Current Configuration:
{
    "name": "Mac",
    "compilerPath": "/usr/bin/clang++",
    "includePath": [
        "/Users/marpaia/git/cimlr/cimlr/**",
        "/Users/marpaia/git/cimlr/cimlr/build/**",
        "/opt/homebrew/include",
        "/opt/homebrew/opt/libomp/include"
    ],
    "defines": [
        "_LIBCPP_ENABLE_EXPERIMENTAL",
        "_LIBCPP_STD_VER=23"
    ],
    "macFrameworkPath": [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
    ],
    "cStandard": "c23",
    "cppStandard": "c++23",
    "intelliSenseMode": "clang-arm64",
    "compilerArgs": [
        "-fexperimental-library",
        "-stdlib=libc++",
        "-std=c++23"
    ],
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "/usr/bin/clang++",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "/Users/marpaia/git/cimlr/cimlr/**",
            "/Users/marpaia/git/cimlr/cimlr/build/**",
            "/opt/homebrew/include",
            "/opt/homebrew/opt/libomp/include",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.formatting": "clangFormat"
}
Additional Tracked Settings:
{
    "editorTabSize": 4,
    "editorInsertSpaces": true,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {
        "*.h.in": "cpp",
        "*.cmake.in": "cmake"
    },
    "filesExclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true
    },
    "filesAutoSaveAfterDelay": false,
    "editorInlayHintsEnabled": true,
    "editorParameterHintsEnabled": true,
    "searchExclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.code-search": true
    },
    "workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.22.11.0
Current database path: /Users/marpaia/Library/Caches/vscode-cpptools/527954c535fb49717f7dab8f4b3b48c9/.browse.VC.db
Translation Unit Mappings:
[ /Users/marpaia/git/cimlr/cimlr/cimlr/cli/CommandLine.cpp - source TU]:
Translation Unit Configurations:
[ /Users/marpaia/git/cimlr/cimlr/cimlr/cli/CommandLine.cpp ]
    Process ID: 51969
    Memory Usage: 541 MB
    Compiler Path: /usr/bin/clang++
    Includes:
        /opt/homebrew/include
        /opt/homebrew/Cellar/libomp/19.1.6/include
        /Users/marpaia/git/cimlr/cimlr
    System Includes:
        /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/include/c++/v1
        /Library/Developer/CommandLineTools/usr/lib/clang/16/include
        /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/include
        /Library/Developer/CommandLineTools/usr/include
    Frameworks:
        /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/System/Library/Frameworks
    Defines:
        _LIBCPP_ENABLE_EXPERIMENTAL
        _LIBCPP_STD_VER=23
        __has_feature(experimental_library)=1
    Standard Version: c++23
    IntelliSense Mode: macos-clang-arm64
    Other Flags:
        --clang
        --clang_version=170006
Total Memory Usage: 541 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 14024
Number of files parsed: 2141

Other Extensions

No response

Additional context

IntelliSense error message:

    no operator "|" matches these operands
    operand types are: std::__1::ranges::drop_while_view<std::__1::basic_string_view<char, std::__1::char_traits<char>>, int (*)(int _c)> | const std::__1::ranges::views::__reverse::__fn

The code compiles and runs correctly with Clang, suggesting this is an IntelliSense limitation with C++23 ranges features.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jan 8, 2025

@marpaia What is the type of flags in your code sample? I'm assuming std::string_view...umm, but that doesn't seem to compile.

@sean-mcmanus sean-mcmanus self-assigned this Jan 8, 2025
@sean-mcmanus sean-mcmanus added bug Language Service more info needed The issue report is not actionable in its current state labels Jan 8, 2025
@sean-mcmanus sean-mcmanus added more info needed The issue report is not actionable in its current state and removed more info needed The issue report is not actionable in its current state labels Jan 8, 2025
@marpaia
Copy link
Author

marpaia commented Jan 9, 2025

Hey @sean-mcmanus, thanks for taking a look at this. It is indeed a std::string_view. Here is the whole function:

std::vector<std::string> CommandLine::splitFlags(const std::string_view flags) {
  std::vector<std::string> result;

  for (const auto flag : flags | std::views::split(',')) {
    std::string_view flagView(flag.begin(), flag.end());
    auto trimmed = flagView | std::views::drop_while(isspace) | std::views::reverse | std::views::drop_while(isspace) |
                   std::views::reverse;

    if (!trimmed.empty()) {
      result.emplace_back(trimmed.begin(), trimmed.end());
    }
  }
  return result;
}

This is the header for reference:

  /**
   * @brief Splits a comma-separated flag list into individual flags
   *
   * Handles whitespace trimming and empty segments.
   *
   * @param flags Comma-separated flag list
   * @return Vector of individual flags
   */
  [[nodiscard]] static std::vector<std::string> splitFlags(std::string_view flags);

Let me know if you want me to provide the whole header and implementation file and/or any of the rest of my build configurations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Language Service more info needed The issue report is not actionable in its current state
Projects
Status: No status
Development

No branches or pull requests

2 participants