an example/test uses a dangling reference
まだ誰も着手していません。
評価
調査の方向性
libs/local_function/test/return_assign.cpp から始め、既存のテストを実行して、一時オブジェクトの場合とローカル変数の場合を比較します。返された boost::function が束縛された参照をどのように保持するかを追跡し、そのうえで安全なテスト動作として意図されているものを判断します。完了条件は、例が dangling reference に依存しなくなり、関連する Lifetime のケースが正しくカバーされていることです。
索引モデルが issue の本文から書いたものです。
説明
libs/local_function/test/return_assign.cpp uses a dangling reference:
#include <boost/local_function.hpp>
#include <boost/function.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
//[return_assign
void call1(boost::function<int (int) > f) { BOOST_TEST(f(1) == 5); }
void call0(boost::function<int (void)> f) { BOOST_TEST(f() == 5); }
boost::function<int (int, int)> linear(const int& slope) {
int BOOST_LOCAL_FUNCTION(const bind& slope,
int x, default 1, int y, default 2) {
return x + slope * y;
} BOOST_LOCAL_FUNCTION_NAME(lin)
boost::function<int (int, int)> f = lin; // Assign to local variable.
BOOST_TEST(f(1, 2) == 5);
call1(lin); // Pass to other functions.
call0(lin);
return lin; // Return.
}
void call(void) {
boost::function<int (int, int)> f = linear(2); // create temporary, bind reference to temporary
BOOST_TEST(f(1, 2) == 5); // !!!!!!!!!!!!!!!!!!!!!!!! use the reference
}
//]
int main(void) {
call();
return boost::report_errors();
}
changing the target from temporary to local variable can let the test fail:
#include <boost/local_function.hpp>
#include <boost/function.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <iostream>
//[return_assign
void call1(boost::function<int(int) > f) { BOOST_TEST(f(1) == 5); }
void call0(boost::function<int(void)> f) { BOOST_TEST(f() == 5); }
boost::function<int(int, int)> linear(const int& slope) {
int BOOST_LOCAL_FUNCTION(const bind & slope,
int x, default 1, int y, default 2) {
return x + slope * y;
} BOOST_LOCAL_FUNCTION_NAME(lin)
boost::function<int(int, int)> f = lin; // Assign to local variable.
BOOST_TEST(f(1, 2) == 5);
call1(lin); // Pass to other functions.
call0(lin);
return lin; // Return.
}
void call1(void) {
boost::function<int(int, int)> f = linear(2);
BOOST_TEST(f(1, 2) == 5); // !!!!!!!!!!!!!!!!!!!!!!!! test passed, although dangling reference
}
void call2(void) {
int a = 2;
boost::function<int(int, int)> f = linear(a);
a = 3;
BOOST_TEST(f(1, 2) == 5); // !!!!!!!!!!!!!!!!!!!!!!!! test failed
}
//]
int main(void) {
call1();
call2();
return boost::report_errors();
}
- 主要言語
- C++
- スター
- 11
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
boostorg/local_function のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
boostorg/local_function#11 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 55/100
boostorg/local_function の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Component: GLib
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
brave/brave-browser#59300 ·
-
Mute ydb/tests/functional/dstool/test_canonical_requests.py.Test.test_group_take_snapshot in main オープンai_reviewed
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ydb-platform/ydb#53974 · コメント 3 件 ·