From 1eda841d320083d037eb90e1728e7df60328c8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 3 Sep 2021 11:03:22 +0200 Subject: [PATCH] workaround user taking ref to temporary If D is a temporary, it's lifetime extension is done when we go out of the scope of choose_parameter so the const D& returned is dangling --- BGL/include/CGAL/boost/graph/Named_function_parameters.h | 6 ++++++ BGL/test/BGL/test_cgal_bgl_named_params.cpp | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/Named_function_parameters.h b/BGL/include/CGAL/boost/graph/Named_function_parameters.h index acad6c9b93b..4738b8e4db0 100644 --- a/BGL/include/CGAL/boost/graph/Named_function_parameters.h +++ b/BGL/include/CGAL/boost/graph/Named_function_parameters.h @@ -313,6 +313,12 @@ const D& choose_parameter(const internal_np::Param_not_found&, const D& d) return d; } +template +D choose_parameter(const internal_np::Param_not_found&, D&& d) +{ + return d; +} + template T& choose_parameter(T& t, D&) { diff --git a/BGL/test/BGL/test_cgal_bgl_named_params.cpp b/BGL/test/BGL/test_cgal_bgl_named_params.cpp index ab403c28000..c6af93cfee9 100644 --- a/BGL/test/BGL/test_cgal_bgl_named_params.cpp +++ b/BGL/test/BGL/test_cgal_bgl_named_params.cpp @@ -43,10 +43,13 @@ void test_values_and_types(const NamedParameters& np) } template -void test_no_copyable(const NamedParameters&) +void test_no_copyable(const NamedParameters& np) { typedef typename inp::Get_param::type NP_type; static_assert( boost::is_same > ::value ); + + const A<4>& a = params::choose_parameter(params::get_parameter_reference(np, inp::edge_index), A<4>(4)); + assert(a.v==4); } template