Skip to content

IntelliSense false error: compound requirement in hidden friend of a class template #14696

Description

Environment

  • OS and Version: Windows 10 Pro 22H2, x64
  • VS Code Version: 1.134.0
  • C/C++ Extension Version: 1.33.8 (cpptools native version 1.33.7.0)
  • Compiler: MSYS2 MinGW-w64 GCC 16.1.0

Bug Summary and Steps to Reproduce

Bug Summary:

IntelliSense incorrectly rejects a constrained hidden-friend function template declared inside a class template.

Sample code:

#include <concepts>

template <typename>
struct Box {
    template <typename T>
    requires requires(T value) {
        { value } -> std::same_as<T&>;
    }
    friend Box operator+(const T&, Box box) {
        return box;
    }
};

Box<int> box;
auto result = 0 + box;

IntelliSense reports:

no operator "+" matches these operands C/C++(349)
minimal_repro.cpp(15, 17): operand types are: int + Box<int>
minimal_repro.cpp(15, 17): substituting "<int>" for function template "operator+" failed constraints
minimal_repro.cpp(15, 17): atomic constraint evaluates to false
minimal_repro.cpp(15, 17): built-in operator+(<promoted arithmetic>, <promoted arithmetic>) does not match because argument #2 does not match parameter
minimal_repro.cpp(15, 17): built-in operator+(<pointer to object>, <ptrdiff_t>) does not match because argument #1 does not match parameter
minimal_repro.cpp(15, 17): built-in operator+(<ptrdiff_t>, <pointer to object>) does not match because argument #2 does not match parameter

Expected behavior:

There should be no error. value is an lvalue expression, so decltype((value)) is T& and the compound requirement is satisfied.

GCC 16.1 accepts the file with no output:

g++ -std=c++23 -fsyntax-only -Wall -Wextra -Wpedantic minimal_repro.cpp

It also accepts the file with -std=c++20.

Configuration and Logs

No c_cpp_properties.json is used; the configuration comes from C_Cpp.default.* settings.
Workspace-specific paths have been replaced with _, and unrelated entries have been omitted.

-------- Diagnostics
Version: 1.33.8
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "D:/_/**",
        "C:/msys64/mingw64/include"
    ],
    "windowsSdkVersion": "10.0.22621.0",
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "cStandard": "c23",
    "cppStandard": "c++23",
    "intelliSenseMode": "windows-gcc-x64",
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "mergeConfigurations": false,
    "compilerPath": "C:/msys64/mingw64/bin/g++.exe",
    "compilerPathIsExplicit": true,
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.33.7.0
Translation Unit Mappings:
[ D:\_\minimal_repro.cpp - source TU]:
Translation Unit Configurations:
[ D:\_\minimal_repro.cpp ]
    Compiler Path: C:\msys64\mingw64\bin\g++.exe
    Language: C++
    Include Paths:
        system include: C:\msys64\mingw64\include\c++\16.1.0
        system include: C:\msys64\mingw64\include\c++\16.1.0\x86_64-w64-mingw32
        system include: C:\msys64\mingw64\include\c++\16.1.0\backward
        system include: C:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\16.1.0\include
        system include: C:\msys64\mingw64\include
        system include: C:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\16.1.0\include-fixed
        include (recursive): D:\_
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: c++23
    IntelliSense Mode: windows-gcc-x64
    Other Flags:
        --g++
        --gnu_version=160100

Other Extensions

No response

Additional context

  • Changing template <typename> struct Box to struct Box removes the IntelliSense error.

  • Replacing { value } -> std::same_as<T&>; with the simple requirement value; removes the IntelliSense error.

  • The following self-type variant is still incorrectly evaluated as false:

    { value } -> std::same_as<decltype((value))>;

This may be related to the general class of GCC 16 IntelliSense errors tracked in #14464, but it is different from the cases listed there. That issue was assigned to the 1.33.5 milestone, while this reproduction still occurs with C/C++ extension 1.33.8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions