Skip to content

Cannot deduce class template arguments #12299

@mbenkmann

Description

@mbenkmann

Environment

Version: 1.89.0
Commit: b58957e67ee1e712cebf466b995adf4c5307b2bd
Date: 2024-05-01T02:08:25.066Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Linux x64 6.6.30

  • C/C++ Extension Version:
    v1.20.5

Bug Summary and Steps to Reproduce

Steps to reproduce:

  1. Put the following code into a file foo.cpp.
  2. Apply the below c_cpp_properties.json to set the "cppStandard": "gnu++20".
struct EndOfScan
{
    bool loop;
    constexpr EndOfScan(bool l) : loop(l){};
};

struct OverrideCR
{
    int ormask;
    int andmask;
    constexpr OverrideCR(int a, int o) : ormask(o), andmask(a){};
    constexpr OverrideCR() : ormask(0), andmask(-1){};
};

constexpr EndOfScan Stop(true);
constexpr OverrideCR Override;

template <typename TInstr, typename TNext>
struct Scan
{
    TInstr i;
    TNext n;

    template <class... Cs>
    constexpr Scan(TInstr _i, Cs... cs) : i(_i), n(cs...){};
};

template <>
struct Scan<EndOfScan, void>
{
    EndOfScan i;
    constexpr Scan(EndOfScan eos) : i(eos){};
};

template <class... Cs>
Scan(EndOfScan e) -> Scan<EndOfScan, void>;

template <class C, class... Cs>
Scan(C c, Cs... cs) -> Scan<C, decltype(Scan{cs...})>;

extern const Scan test = {Override, Stop};

Expected behavior:

There should be no error squiggles and nothing listed in the Problems tab.

Actual behavior:

Scan test is underline as error and the Problems tab has the error cannot deduce class template arguments (as well as a follow up error that's a result from the inability to deduce the template parameters).

Configuration and Logs

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++20",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}
-------- Diagnostics - 5/13/2024, 9:33:39 PM
Version: 1.20.5
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "/tmp/bug/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "cStandard": "c17",
    "cppStandard": "gnu++20",
    "intelliSenseMode": "linux-gcc-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "/usr/bin/gcc",
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "/tmp/bug/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.20.5.0
Translation Unit Mappings:
[ /tmp/bug/foo.cpp - source TU]:
Translation Unit Configurations:
[ /tmp/bug/foo.cpp ]:
    Process ID: 18390
    Memory Usage: 16 MB
    Compiler Path: /usr/bin/gcc
    Includes:
        /usr/include/c++/9
        /usr/include/x86_64-linux-gnu/c++/9
        /usr/include/c++/9/backward
        /usr/lib/gcc/x86_64-linux-gnu/9/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=90400
Total Memory Usage: 16 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 27212



### Other Extensions

_No response_

### Additional context

I've checked on godbolt that clang can deduce the template arguments for this code correctly. And the project that contains the more complex version of this code compiles with no errors and warnings with GCC.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions