Constructing a protocol_view from a valueless protocol is undiagnosed, and calls through it hit a null function pointer
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
A moved-from protocol has object_ == nullptr and vtable_ == &null_vtable,
whose member entries are null function pointers. Calling a member function on
it directly is caught in debug builds: method_thunk::operator() asserts
!valueless_after_move() before dispatching.
Since #244 and #272 a protocol_view<I> or protocol_view<const I> constructs
implicitly from a protocol<I, A>&, copying object_ and vtable_. Nothing
checks the source, so a valueless protocol converts silently, and the thunk
assert is if constexpr (is_protocol_v<ProtocolType>), so it is compiled out
for views. A member call through such a view calls a null function pointer with
no diagnostic, even in a debug build.
protocol<Shape> a{Circle{}};
protocol<Shape> b = std::move(a); // a is valueless
protocol_view<const Shape> v = a; // accepted; comment says "Precondition: p is not valueless"
v.area(); // release: null call; debug: also null call
The from-protocol constructors document the precondition in a comment
(protocol.hh, both protocol_view specializations) but do not enforce it.
Suggested fix, small enough for one PR:
assert(!p.valueless_after_move())in the two from-protocol constructors.- Drop the
is_protocol_vgate inmethod_thunkand assertobject_ != nullptr
instead, which covers protocol and view alike. A view'sobject_is otherwise
never null. - A death test for each path.
#208 settled the direct-call case as a precondition violation diagnosed by an
assert in debug builds; this extends the same contract to views. Raised in the
review of #272, where it was agreed to be out of scope there but worth fixing.
- 主要言語
- C++
- スター
- 12
- フォーク
- 4
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 15
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jbcoe/cc-protocol のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jbcoe/cc-protocol#507 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jbcoe/cc-protocol#455 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jbcoe/cc-protocol#407 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
jbcoe/cc-protocol#194 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
jbcoe/cc-protocol#513 ·
メンテナーはふだん 1 日以内に返信
jbcoe/cc-protocol の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
itinance/react-native-fs#1270 ·
-
clang:frontend clang:openmp crash
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
llvm/llvm-project#245442 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
ai_p1 comp-sql-syntax
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ClickHouse/ClickHouse#133888 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜2日 初心者へのやさしさ 65/100