Skip to content

<sstream>: C2079 for std::basic_istream<char,std::char_traits<char>> error when importing <sstream> as header unit with two modules that include it in GMF (triple bug) #6389

Description

@Quan-huayan

Description

When mixing C++20 modules and header units under specific conditions, the MSVC compiler emits error C2079: "_Ok" uses undefined class "std::basic_istream<...>::sentry".
The issue is reproducible with both the latest stable (19.51.36252) and preview (19.52.36520) toolchains, and only occurs when using /MD or /MDd (dynamic CRT). Building with /MT or /MTd succeeds.

The following minimal repro uses three module interface files and one header unit (<sstream>). It also shows in my repository: https://github.com/Quan-huayan/BugReports/blob/main/20260801/README.md.

// module1.ixx
module;

#include <sstream>

export module module1;

void fun1(std::istream& ss) {
    std::string s;
    std::getline(ss, s);
}
// module2.ixx
module;

#include <sstream>

export module module2;

void fun2(std::istream& ss) {
    std::string s;
    std::getline(ss, s);
}
// module3.ixx
module;

//#include <sstream>

export module module3;

import module1;
import module2;
import <sstream>;

void fun3(std::istream& ss) {
    std::string s;
    std::getline(ss, s);
}

Command-line test case

All commands are executed from D:\BugReports\20260801.

D:\BugReports\20260801>set CL=/nologo /MDd /c /EHsc /std:c++20 /permissive- /utf-8 /TP /FS

D:\BugReports\20260801>set _CL_= /D _MBCS /D WIN32 /D _WINDOWS /ifcSearchDir "out\\" /I"E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/include" /I"E:/Windows Kits/10/Include/10.0.26100.0/ucrt"

D:\BugReports\20260801>"E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/bin/Hostx64/x64/cl.exe" /ifcOutput "out\module1.ifc" /Fo"out\module1.obj" /interface module1.ixx
module1.ixx

D:\BugReports\20260801>"E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/bin/Hostx64/x64/cl.exe" /ifcOutput "out\sstream.ifc" /Fo"out\sstream.obj" /exportHeader "E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/include/sstream"
sstream

D:\BugReports\20260801>"E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/bin/Hostx64/x64/cl.exe" /ifcOutput "out\module2.ifc" /Fo"out\module2.obj" /interface module2.ixx
module2.ixx

D:\BugReports\20260801>"E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/bin/Hostx64/x64/cl.exe" /headerUnit "E:/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.52.36520/include\sstream=out\sstream.ifc" /ifcOutput "out\module3.ifc" /Fo"out\module3.obj" /interface module3.ixx
module3.ixx
E:\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.52.36520\include\string(33): error C2079: “_Ok”使用未定义的 class“std::basic_istream<char,std::char_traits<char>>::sentry”
E:\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.52.36520\include\string(33): note: 模板实例化上下文(最早的实例化上下文)为
module3.ixx(13): note: 请参阅正在编译的函数 模板 实例化或专用化“std::basic_istream<char,std::char_traits<char>> &std::getline<char,std::char_traits<char>,std::allocator<char>>(std::basic_istream<char,std::char_traits<char>> &,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)”的引用
E:\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.52.36520\include\string(86): note: 请参阅正在编译的函数 模板 实例化或专用化“std::basic_istream<char,std::char_traits<char>> &std::getline<char,std::char_traits<char>,std::allocator<char>>(std::basic_istream<char,std::char_traits<char>> &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,const _Elem)”的引用
        with
        [
            _Elem=char
        ]

The error occurs during compilation of module3.ixx, when it imports both module1, module2 and the header unit <sstream>.

Expected behavior

Compilation should succeed without any C2079 error. The nested type std::basic_istream::sentry should remain fully defined when shared across modules, as it is a required type for instantiations of std::getline and other stream operations.

STL version

Microsoft (R) C/C++ Optimizing Compiler Version 19.52.36520 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

This is the latest preview release as of the date of this report. The same behavior is observed with the latest stable version 19.51.36252.

  • Platform: x64
  • Windows SDK: 10.0.26100.0
  • Compiler flags: /std:c++20 /permissive- /EHsc /utf-8 /TP, with /MDd (or /MD) required to trigger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerCompiler work involvedmodulesC++23 modules, C++20 header units

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions