Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78461 - in sandbox/type_erasure: boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-05-13 16:48:45


Author: steven_watanabe
Date: 2012-05-13 16:48:45 EDT (Sun, 13 May 2012)
New Revision: 78461
URL: http://svn.boost.org/trac/boost/changeset/78461

Log:
Avoid silently passing through unbound placeholders. This fixes an accepts invalid error demonstrated by the test case.
Added:
   sandbox/type_erasure/libs/type_erasure/test/fail_binding_convert_no_mapping.cpp (contents, props changed)
Text files modified:
   sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp | 46 ++++++++++++++++++++++++++++++++++++++-
   sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp | 10 ++++++-
   sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam | 1
   3 files changed, 53 insertions(+), 4 deletions(-)

Modified: sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp 2012-05-13 16:48:45 EDT (Sun, 13 May 2012)
@@ -25,6 +25,7 @@
 #include <boost/mpl/fold.hpp>
 #include <boost/mpl/transform.hpp>
 #include <boost/mpl/copy.hpp>
+#include <boost/mpl/at.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/type_erasure/detail/get_placeholders.hpp>
 #include <boost/type_erasure/detail/rebind_placeholders.hpp>
@@ -43,6 +44,47 @@
 
 namespace detail {
 
+struct substitution_map_tag {};
+
+template<class M>
+struct substitution_map
+{
+ typedef substitution_map_tag tag;
+ typedef M map_type;
+};
+
+}
+}
+
+namespace mpl {
+
+template<>
+struct at_impl< ::boost::type_erasure::detail::substitution_map_tag>
+{
+ template<class Seq, class Key>
+ struct apply
+ {
+ typedef typename ::boost::mpl::eval_if<
+ ::boost::mpl::has_key<typename Seq::map_type, Key>,
+ ::boost::mpl::at<typename Seq::map_type, Key>,
+ ::boost::mpl::identity<Key>
+ >::type type;
+ };
+};
+
+template<>
+struct has_key_impl< ::boost::type_erasure::detail::substitution_map_tag>
+{
+ template<class Seq, class Key>
+ struct apply : boost::mpl::true_
+ {};
+};
+
+}
+
+namespace type_erasure {
+namespace detail {
+
 template<class Out, class T>
 struct insert_concept
 {
@@ -281,7 +323,7 @@
             ::boost::mpl::_1,
             ::boost::type_erasure::detail::rebind_placeholders<
                 ::boost::mpl::_2,
- substitutions
+ ::boost::type_erasure::detail::substitution_map<substitutions>
>
>
>::type basic;
@@ -308,7 +350,7 @@
 {
     typedef typename ::boost::type_erasure::detail::rebind_placeholders<
         Concept,
- Map
+ ::boost::type_erasure::detail::substitution_map<Map>
>::type transformed;
     typedef typename ::boost::mpl::eval_if<
         ::boost::is_same<transformed, void>,

Modified: sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp 2012-05-13 16:48:45 EDT (Sun, 13 May 2012)
@@ -17,13 +17,15 @@
 #include <boost/mpl/identity.hpp>
 #include <boost/mpl/at.hpp>
 #include <boost/mpl/has_key.hpp>
-#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
 #include <boost/preprocessor/cat.hpp>
 #include <boost/preprocessor/iteration/iterate.hpp>
 #include <boost/preprocessor/repetition/enum.hpp>
 #include <boost/preprocessor/repetition/enum_params.hpp>
 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
 #include <boost/type_erasure/config.hpp>
+#include <boost/type_erasure/is_placeholder.hpp>
 
 namespace boost {
 namespace type_erasure {
@@ -42,8 +44,12 @@
 template<class T, class Bindings>
 struct rebind_placeholders_in_argument
 {
+ BOOST_MPL_ASSERT((boost::mpl::or_<
+ ::boost::mpl::not_< ::boost::type_erasure::is_placeholder<T> >,
+ ::boost::mpl::has_key<Bindings, T>
+ >));
     typedef typename ::boost::mpl::eval_if<
- ::boost::mpl::has_key<Bindings, T>,
+ ::boost::type_erasure::is_placeholder<T>,
         ::boost::mpl::at<Bindings, T>,
         ::boost::mpl::identity<T>
>::type type;

Modified: sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam (original)
+++ sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam 2012-05-13 16:48:45 EDT (Sun, 13 May 2012)
@@ -34,6 +34,7 @@
 run test_deduced.cpp /boost//unit_test_framework ;
 run test_same_type.cpp /boost//unit_test_framework ;
 
+compile-fail fail_binding_convert_no_mapping.cpp ;
 compile-fail fail_increment_discard_const.cpp ;
 
 compile-fail fail_ref_discard_const.cpp ;

Added: sandbox/type_erasure/libs/type_erasure/test/fail_binding_convert_no_mapping.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/fail_binding_convert_no_mapping.cpp 2012-05-13 16:48:45 EDT (Sun, 13 May 2012)
@@ -0,0 +1,25 @@
+// Boost.TypeErasure library
+//
+// Copyright 2011 Steven Watanabe
+//
+// Distributed under the Boost Software License Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// $Id$
+
+#include <boost/type_erasure/binding.hpp>
+#include <boost/type_erasure/builtin.hpp>
+#include <boost/type_erasure/static_binding.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/pair.hpp>
+
+using namespace boost::type_erasure;
+
+int main()
+{
+ binding< boost::mpl::vector<typeid_<_a>, typeid_<_b> > > b1(
+ make_binding<boost::mpl::map<boost::mpl::pair<_a, int>, boost::mpl::pair<_b, int> > >());
+ binding< typeid_<_a> > b2(b1, make_binding<boost::mpl::map<> >());
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk