r/cpp • • 3d ago

MSVC automatic import std::vector bug

https://developercommunity.visualstudio.com/t/MSVC-C20-modules-expose-std::vector-on/11135469?sort=newest&scope=follow
//math.ixx
module;
#include <vector>
export module math;
//nothing is exported

//main.cpp  Vs2026 18.9.2
import math;
int main()
{
std::vector<char> value = { 'a', 'b', 'c'}; // OK, but why?

return 0;
}
6 Upvotes

7 comments sorted by

7

u/manni66 2d ago
module;
//#include <vector>
export module math;
import std;

produces the expected error message: "error C2039: 'vector': is not a member of 'std'"

10

u/kamrann_ 2d ago

MSVC's modules implementation is broken on the "too permissive" side of things in numerous ways that probably tend to go unnoticed if it's your only compiler. Really fundamental stuff. It incorrectly allows use of names that are imported transitively without an intermediate "export import". It allows declarations from one module to be defined in an another. Every time I take code that I've been developing for a while on Windows and try to compile on Linux with clang, it invariably shows the code to have been totally broken.

4

u/starfreakclone MSVC FE Dev 19h ago

Most of those, "declare a type in one module and define it in another" should be fixed in more recent versions of the compiler.

The issue above has been a perennial problem and is deeply rooted in how name lookup wants to find global symbols—this is what makes it hard to protect GMF text from name lookup in an importing TU. As for why vector is there at all: this is due to it having an explicit specialization for bool. Since the compiler is required to coalesce all specializations of a template that originate from the same module, it forces the compiler to first check if vector already exists on import, if not, it will create it and emit a stub for the specialization it holds.

6

u/fortsnek274 2d ago

Well, it'd probably get fixed. Unless it gets deprioritised.

7

u/ironykarl 2d ago

So, it'll either get fixed or it won't? 

4

u/Daniela-E Living on C++ trunk, WG21 |🇩🇪 NB 3d ago