Home > other >  Visual Studio 2022 - Modules (Intellisense errors)
Visual Studio 2022 - Modules (Intellisense errors)

Time:07-30

I have 3 files, namely engineering.cpp, engineering.ixx and system.ixx. Contents briefly are:

system.ixx:

export module sys;
export import :engineering;

engineering.ixx

module;

#include <string>
#include <vector>

export module sys:engineering;

namespace sys::engineering
{

    export class Psychrometry
    {
       //more code here
    }
}

engineering.cpp

module;

#include <sstream>

module sys:engineering;

namespace sys::engineering
{
     //implementation of the class
}

In another cpp file I use it as:

import sys;
sys::engineering::Psychrometry psy;

The project compiles and works well but in engineering.cpp intellisense gives 99 errors and code-completion and other basic facilities dont work.

However, if I make the following change to engineering.cpp:

//instead of module sys:engineering
module sys;

Now intellisense works well and the project still compiles and works. However, to my understanding the first approach (module sys:engineering) is correct rather than (module sys).

What am I missing? Thanks in advance.

(Visual Studio Community 2022 (64-bit) - Current Version 17.2.6)

CodePudding user response:

Two module units cannot use the same module partition name. As such, sys:engineering cannot be used in two module units. No diagnostic is required, which is why you don't get a compile error.

Also, if engineering.cpp is going to be a module implementation partition, then it must explicitly import the module if you want to use any of the declarations exported by the module interface. Non-partition implementation units automatically import the module interface.

The only reason to make a module implementation unit a partition is if you want to import that file elsewhere (perhaps to share declarations internal to the module). Otherwise, just make them non-partition implementation units.

  • Related