Repository navigation
Bug: Spurious IntelliSense errors with C++20 Modules #1610
Description
Activity
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

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.vcxprojfile and add the property<SuppressStartupBanner>false</SuppressStartupBanner>to theClCompileitem. After that, building the project will print theclcommand line that was used.
Next, insert the/BEoption right before the name of the source file you’re currently building (e.g.,main.cpp), open a VS Command Prompt,cdto the.vcxprojdirectory, 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.cppI 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.
Reacted by rtanabe999, pjmlp, Makoto Sakaguchi and Victor Derks
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:
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
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