`<sstream>`: basic_stringbuf C++20 constructors call _Getal()/_Release_to_buffer() breaks user specializations of basic_string

オープン
#6,374 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
tooling

調査の方向性

の実装で、_Getal() と _Release_to_buffer() を呼び出す C++20 の basic_stringbuf コンストラクターから始めます。提供された basic_string の明示的特殊化を basic_istringstream、basic_ostringstream、basic_stringstream について再現し、これらの MSVC 内部メンバーに依存せずにケースが C++20 でコンパイルできることを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug vNext

Command-line test case

#include <sstream>
#include <string>

namespace std {
    template<>
    class basic_string<MyChar> 
    { /* minimal impl */ };
}

// Triggers C2039: '_Getal' is not a member of std::basic_string<MyChar>
std::basic_istringstream<MyChar> s;

With /std:c++20, including and using std::basic_istringstream where std::basic_string is explicitly specialized produces:

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\include\sstream(50): error C2039: "_Getal" ist kein Member von "std::basic_string<MyChar,std::char_traits,std::allocator>".
Siehe Deklaration von "std::basic_string<MyChar,std::char_traits,std::allocator>"

The C++20 constructor basic_stringbuf(basic_string<E,T,A>&&, openmode) calls _Str._Getal() and subsequently _Str._Release_to_buffer(), both of which are MSVC-internal implementation details absent from user specializations. The same code compiles without error in C++17 mode and on GCC/Clang.

Expected behavior

Instantiating std::basic_istringstream<T>, std::basic_ostringstream<T>, or std::basic_stringstream<T> with a user-defined character type T whose std::basic_string<T> is explicitly specialized should compile without errors.

The C++ standard ([namespace.std] p2) permits adding explicit specializations of standard library class templates to namespace std for program-defined types, provided the specialization meets the standard library requirements for the original template. Footnote 140 further states:

"Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization that meets the minimum requirements of this document."

std::basic_stringbuf<T> is standard library code that instantiates std::basic_string<T>. It must therefore work with any conforming user specialization of std::basic_string<T>. The implementation should not require the presence of MSVC-internal methods (_Getal, _Release_to_buffer) that are not part of the std::basic_string interface mandated by the standard and that cannot be present on a user-provided specialization.

STL version

Microsoft (R) C/C++-Optimierungscompiler Version 19.44.35226 für x64

主要言語
C++
スター
11.2k
フォーク
1.7k
平均マージ
4日 4時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/STL のほかの issue

microsoft/STL の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。