`<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)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
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.
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.
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 14
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/STL
-
LWG
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
generator LWG
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
LWG
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
`<__msvc_math.hpp>`: `_USE_MATH_DEFINES` is ignored after the first `<math.h>` include under `/Zc:cmath`Possibly taken @tiagomacarios claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
ClickHouse/clickhouse-odbc#680 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ionut-mihalache/aqua#31 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
needs-kind
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
villagesql/villagesql-server#1702 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/vcpkg-tool#2191 · 1 reaction ·
Maintainers usually reply within 1 day