vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Variadic template causes "no instance of function template matches the argument list"

Open ChrisBlueStone opened this issue 3 years ago • 9 comments

Bug type: Language Service

When using a variadic template on a function, the intellisense gets angry whenever the function is called and can't seem to resolve it, displaying the message no instance of function template matches the argument list. The "Go to definition" function works fine though, and the program compiles just fine.

I've noticed similar issues reported that trigger the intellisense message I'm getting, but I'm not sure any of them are the result of the same underlying issue.

  • OS and Version: Windows 10.0.19043 Build 19043
  • VS Code Version: 1.64.2
  • C/C++ Extension Version: 1.8.4
  • All extensions except for cpptools are disabled, and the issue only manifests when this extension is enabled.
  • g++ --version: 6.3.0

Steps to reproduce

  1. Create a new file and paste in example code below.
  2. Save the file and notice issue does not manifest.
  3. Click File > Open Folder
  4. Select the folder where you saved the file.
  5. Intellisense will show errors on lines 47 and 54. Program compiles just fine.

Expected behavior No red squiggles.

Code sample

struct A
{
    template <class Func, typename Output, typename ...Args>
    bool Call(Output &output, Args& ...args, Func f = Func()) const
    {
        return f(output, args...);
    }

    template <class Func, typename Output, typename ...Args>
    bool Call2(Output &output, Func f = Func()) const
    {
        return f(output);
    }

};

struct B
{
    template <class Func, typename Output, typename ...Args>
    static bool Call(Output &output, Args& ...args, Func f = Func())
    {
        return f(output, args...);
    }

    template <class Func, typename Output, typename ...Args>
    static bool Call2(Output &output, Func f = Func())
    {
        return f(output);
    }
};

struct F
{
    bool operator()(unsigned int &i) const
    {
        return 1 != (i = i % 2 ? i * 3 + 1: i >> 1);
    }
};

int main(int argc, char **argv)
{
    unsigned int i = 100;
    
    A a;
    a.Call<F>(i);
//    ~~~~
// no instance of function template "A::Call" matches the argument list C/C++(304)

    a.Call2<F>(i); // OK


    B::Call<F>(i);
//  ~
// no instance of function template "B::Call" matches the argument list C/C++(304)

    B::Call2<F>(i); // OK

    return 0;
}

ChrisBlueStone avatar Mar 08 '22 03:03 ChrisBlueStone