microsoft / microsoft/STL

`<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)

Open
#6,389 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

compiler modules
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with module1.ixx, module2.ixx, module3.ixx, and the header-unit commands under /MD or /MDd; compare with /MT or /MTd. The report does not identify an STL source file or test, so first locate the modules/header-unit handling involved, then verify that compiling module3.ixx succeeds without C2079 and preserves the sentry definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.