r/cpp • u/Expert_Sheepherder24 • 6d 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;
}
7
Upvotes
View all comments
Show parent comment
8
u/starfreakclone MSVC FE Dev 4d 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.