Visitar URL original
Bug: Spurious IntelliSense errors with C++20 Modules · Issue #1610 · microsoft/cppwinrt · GitHub
Skip to content

Bug: Spurious IntelliSense errors with C++20 Modules #1610

Description

Version

3.0.260715.1

Summary

A simple project that uses C++/WinRT with the new C++20 Modules feature can build successfully with MSVC 14.52 Preview in Visual Studio Insiders, but has IntelliSense errors in the IDE that get in the way of return type deduction and similar. For instance, the example code causes this IntelliSense error:

function "winrt::Windows::Foundation::IUnknown::operator new(size_t)" (declared at line 2117 of module "winrt_base" ("D:\...\winrtmodcom\x64\Debug\Generated Files\winrt\base.h")) cannot be referenced -- it is a deleted function

More likely than not, this is simply an IDE and IntelliSense bug and I've reported it as such in DevCom-11123562. Anyone who cares about this scenario is welcome to upvote it. Having said that, if there's any workaround that can be implemented on the cppwinrt side to mitigate these IntelliSense failures, it would be a welcome improvement to the user experience.

Reproducible example

import std;
import winrt_base;
import winrt.Windows.Foundation;

winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> GetStringAsync()
{
    co_return L"Hello, World!";
}

winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> foo()
{
    auto str = co_await GetStringAsync(); // IntelliSense labels this <error type> instead of figuring out it is a winrt::hstring.
    co_return str;
}

Expected behavior

IntelliSense should be fully functional with cppwinrt C++20 Modules in scenarios that work correctly with header files.

Actual behavior

IntelliSense reports spurious E1776 errors and fails to deduce return types

Additional comments

No response

Activity

  1. hoshiizumiya commented on Jul 23, 2026

    @hoshiizumiya

    I could say that it can not work at all in my module proj (C++23). VS xaml intellisense too. It's my feedback link https://developercommunity.visualstudio.com/t/XAML-IntelliSense-and-Hot-Reload-stop-wo/11117521

    Image Image
  2. YexuanXiao commented on Jul 23, 2026

    @YexuanXiao
    Contributor

    I believe this is indeed a bug in IntelliSense and the workaround is difficult to implement in C++/WinRT.
    I checked the output from IntelliSense, which is as follows:

    error: failed to load an
              IFC entity reference in module "winrt_base"
                from partition "expr.decl" element 1934 (file position 1113216,
                          relative position 30944)
              detected during:
                instantiation of type "winrt::impl::base_implements<D, I...>" at
                          line 8088
                instantiation of class "winrt::impl::promise_base<Derived,
                          AsyncInterface, TProgress> [with
                          Derived=std::coroutine_traits<winrt::Windows::Foundation:
                          :IAsyncOperation<winrt::hstring>>::promise_type,
                          AsyncInterface=winrt::Windows::Foundation::IAsyncOperatio
                          n<winrt::hstring>, TProgress=void]" at line 4110 of
                          module "winrt.Windows.Foundation"
    

    So it looks like this is caused by a bug in IntelliSense’s support for IFC.

    A limited workaround is to add the following at the top of your source files:

    #ifdef __INTELLISENSE__
    #include "winrt/base.h"
    #endif

    How to debug IntelliSense:

    In the project property pages under C/C++ / General, set Suppress Start Banner to No, or edit the .vcxproj file and add the property <SuppressStartupBanner>false</SuppressStartupBanner> to the ClCompile item. After that, building the project will print the cl command line that was used.
    Next, insert the /BE option right before the name of the source file you’re currently building (e.g., main.cpp), open a VS Command Prompt, cd to the .vcxproj directory, and run the modified command to see the actual output from the IntelliSense engine.

    For modules you have to do a full build of the project first to generate the IFC files, and then run the modified command. In addition, MSBuild currently seems to have a defect where it adds modules to the build command even if they aren’t used. I reported this issue on DevCom. For a C++/WinRT project this results in an extremely long command (around 48 KB), so you need to trim the command line by removing the irrelevant module references. The command I used is:

    cl /c /I"x64\Debug\Generated Files\\" /reference std=R:\ConsoleApplication1\ConsoleApplication1\x64\Debug\microsoft\STL\std.ixx.ifc /reference std.compat=R:\ConsoleApplication1\ConsoleApplication1\x64\Debug\microsoft\STL\std.compat.ixx.ifc /reference winrt.Windows.Foundation=R:\ConsoleApplication1\ConsoleApplication1\x64\Debug\winrt.Windows.Foundation.ixx.ifc /reference winrt_base=R:\ConsoleApplication1\ConsoleApplication1\x64\Debug\winrt_base.ixx.ifc /reference winrt_numerics=R:\ConsoleApplication1\ConsoleApplication1\x64\Debug\winrt_numerics.ixx.ifc /ZI /JMC /W4 /WX- /diagnostics:column /Od /D _DEBUG /D _CONSOLE /D WIN32_LEAN_AND_MEAN /D WINRT_LEAN_AND_MEAN /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++20 /Fo"x64\Debug\\" /Fd"x64\Debug\vc145.pdb" /external:W4 /Gd /TP /FC /errorReport:prompt  /permissive- /bigobj /BE main.cpp
    
  3. YexuanXiao commented on Jul 24, 2026

    @YexuanXiao
    Contributor

    I just received some good news: the MSVC team is preparing to address the issue of IntelliSense's poor support for modules, and we can expect some improvement within this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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