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

Weird interaction with C++20's abbreviated function template #7446

Closed
sam20908 opened this issue Apr 30, 2021 · 3 comments
Closed

Weird interaction with C++20's abbreviated function template #7446

sam20908 opened this issue Apr 30, 2021 · 3 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

@sam20908
Copy link

sam20908 commented Apr 30, 2021

Bug type: Language Service

Describe the bug

  • OS and Version: Windows 10
  • VS Code Version: 1.55.2
  • C/C++ Extension Version: 1.3.1
  • Other extensions you installed (and if the issue persists after disabling them):
  • If using SSH remote, specify OS of remote machine:
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

The language service compiler EDG fails to compile a valid C++20 code when using abbreviated function templates.

There are precisely two problems here: the two occurrences of abbreviated function template parameters

constexpr bind_back_wrap(const Fn &fn, auto &&...args)

and

constexpr auto operator()(auto &&...args)

They cause problems for EDG, but compiles fine with MSVC with C++20 (I used cl /c /MD /std:c++latest main.cpp)

EDG successfully compiles when you replace the occurrences with:

template <typename... Args>
constexpr bind_back_wrap(const Fn &fn, Args &&...args) : fn(fn), back_args{std::forward<Args>(args)...} {}

and

template <typename... Args>
constexpr auto operator()(Args &&...args) const
{
	return std::apply(fn, std::tuple_cat(std::forward_as_tuple(std::forward<Args>(args)...), back_args));
}

Sorry if this repro is a little complex, as I couldn't repro the issue any other way.

Steps to reproduce

  1. Create a main.cpp
  2. Paste the following code:
#include <utility>
#include <functional>
#include <tuple>

template <typename Fn, typename... BackArgs>
struct bind_back_wrap
{
	const Fn &fn;
	std::tuple<BackArgs...> back_args;

	constexpr bind_back_wrap(const Fn &fn, auto &&...args) : fn(fn),
															 back_args{std::forward<decltype(args)>(args)...} {}

	constexpr auto operator()(auto &&...args) const
	{
		return std::apply(fn, std::tuple_cat(std::forward_as_tuple(std::forward<decltype(args)>(args)...), back_args));
	}
};

template <typename Fn, typename... Args>
constexpr auto bind_back(const Fn &fn, Args &&...args)
{
	return bind_back_wrap<Fn, Args...>(fn, std::forward<Args>(args)...);
}

inline constexpr auto add = [](const auto &a, const auto &b) { return a + b; };

int main()
{
	auto foo = bind_back(add, 2);
	foo(1);
}
  1. See error (or compile with cl /BE /c /MD /std:c++latest main.cpp)

Expected behavior

Code should compile fine and no errors

Code sample and logs

  • Code sample

  • Configurations in c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.29.30031/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-msvc-x64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}
  • Logs from running C/C++: Log Diagnostics from the VS Code command palette
-------- Diagnostics - 2021-04-30, 11:15:59 a.m.
Version: 1.3.1
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.19041.0",
    "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.29.30031/bin/Hostx64/x64/cl.exe",
    "cStandard": "c17",
    "cppStandard": "c++20",
    "intelliSenseMode": "windows-msvc-x64",
    "configurationProvider": "ms-vscode.cmake-tools",
    "compilerArgs": [],
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "compilerPathIsExplicit": true,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ C:\Users\Sam Huang\Projects\cpptools-repro-sandbox\main.cpp ]:
    C:\USERS\SAM HUANG\PROJECTS\CPPTOOLS-REPRO-SANDBOX\MAIN.CPP
Translation Unit Configurations:
[ C:\Users\Sam Huang\Projects\cpptools-repro-sandbox\main.cpp ]:
    Process ID: 3964
    Memory Usage: 34 MB
    Compiler Path: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.29.30031/bin/Hostx64/x64/cl.exe
    Includes:
        C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PREVIEW\VC\TOOLS\MSVC\14.29.30031\INCLUDE
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: ms_c++latest
    IntelliSense Mode: windows-msvc-x64
Total Memory Usage: 34 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4809
cpptools/didChangeCppProperties
MSVC intelliSenseMode specified.  Configuring for compiler cl.exe.
Code browsing service initialized
MSVC intelliSenseMode specified.  Configuring for compiler cl.exe.
  Folder: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/PREVIEW/VC/TOOLS/MSVC/14.29.30031/INCLUDE/* will be indexed
  Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/CPPWINRT/ will be indexed
  Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/SHARED/ will be indexed
  Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/UCRT/ will be indexed
  Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/UM/ will be indexed
  Folder: C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/WINRT/ will be indexed
  Folder: C:/USERS/SAM HUANG/PROJECTS/CPPTOOLS-REPRO-SANDBOX/ will be indexed
cpptools/clearCustomConfigurations
Populate include completion cache.
Discovering files...
  Processing folder (non-recursive): C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/PREVIEW/VC/TOOLS/MSVC/14.29.30031/INCLUDE
  Processing folder (recursive): C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/CPPWINRT/
  Processing folder (recursive): C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/SHARED/
  Processing folder (recursive): C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/UCRT/
  Processing folder (recursive): C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/UM/
  Processing folder (recursive): C:/PROGRAM FILES (X86)/WINDOWS KITS/10/INCLUDE/10.0.19041.0/WINRT/
  Processing folder (recursive): C:/USERS/SAM HUANG/PROJECTS/CPPTOOLS-REPRO-SANDBOX/
  Discovering files: 4810 file(s) processed
  1 file(s) removed from database
Done discovering files.
Parsing remaining files...
  Parsing: 0 files(s) processed
Done parsing remaining files.
cpptools/getCodeActions: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 2)
textDocument/didOpen: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp
cpptools/activeDocumentChange: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp
cpptools/textEditorSelectionChange
cpptools/getDocumentSymbols: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 3)
cpptools/textEditorSelectionChange
cpptools/getSemanticTokens: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 4)
cpptools/getDocumentSymbols
  tag parsing file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PREVIEW\VC\TOOLS\MSVC\14.29.30031\INCLUDE\CODEANALYSIS\SOURCEANNOTATIONS.H
idle loop: reparsing the active document
Checking for syntax errors: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp
sending compilation args for C:\USERS\SAM HUANG\PROJECTS\CPPTOOLS-REPRO-SANDBOX\MAIN.CPP
  include: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PREVIEW\VC\TOOLS\MSVC\14.29.30031\INCLUDE
  include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
  include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
  include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
  include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
  include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT
  define: _DEBUG
  define: UNICODE
  define: _UNICODE
  stdver: ms_c++latest
  intelliSenseMode: windows-msvc-x64
Queueing IntelliSense update for files in translation unit of: C:\USERS\SAM HUANG\PROJECTS\CPPTOOLS-REPRO-SANDBOX\MAIN.CPP
cpptools/finishUpdateSquiggles
Error squiggle count: 2
Update IntelliSense time (sec): 0.633
cpptools/getCodeActions: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 5)
cpptools/getFoldingRanges: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 6)
cpptools/abortRequest
cpptools/getFoldingRanges: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 7)
cpptools/getCodeActions: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 8)
cpptools/textEditorSelectionChange
cpptools/getCodeActions: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 9)
cpptools/activeDocumentChange: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp
cpptools/textEditorSelectionChange
idle loop: reparsing the active document
Checking for syntax errors: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp
Queueing IntelliSense update for files in translation unit of: C:\USERS\SAM HUANG\PROJECTS\CPPTOOLS-REPRO-SANDBOX\MAIN.CPP
cpptools/finishUpdateSquiggles
Error squiggle count: 1
Update IntelliSense time (sec): 0.267
cpptools/getSemanticTokens: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 10)
Database safe to open
cpptools/getFoldingRanges: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 11)
cpptools/getCodeActions: file:///c%3A/Users/Sam%20Huang/Projects/cpptools-repro-sandbox/main.cpp (id: 12)

Screenshots

Additional context

@sean-mcmanus sean-mcmanus self-assigned this Apr 30, 2021
@sean-mcmanus sean-mcmanus added bug Language Service Visual Studio Inherited from Visual Studio labels May 1, 2021
@sean-mcmanus sean-mcmanus added this to the Tracking milestone May 1, 2021
@sean-mcmanus
Copy link
Collaborator

Thanks for reporting this. I've filed a bug on our shared VS parser. I'll add the URL once the bug becomes public.

@sean-mcmanus
Copy link
Collaborator

Filed at https://developercommunity.visualstudio.com/t/C20-IntelliSense-error-function-canno/1411924

@sean-mcmanus sean-mcmanus removed their assignment May 1, 2021
@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.12.1 Aug 2, 2022
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Aug 2, 2022
@sean-mcmanus
Copy link
Collaborator

@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2022
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

2 participants