From 4b3e8171fac8eda143c3b82d0ee153fbc20e7e3a Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 7 May 2003 20:41:11 +0000 Subject: [PATCH] Initial re-commit after CVS disk crash [SVN r18348] --- test/Jamfile | 34 ++++++++++++++++++++++++++++++++++ test/implicit_cast.cpp | 34 ++++++++++++++++++++++++++++++++++ test/implicit_cast_fail.cpp | 23 +++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 test/Jamfile create mode 100644 test/implicit_cast.cpp create mode 100644 test/implicit_cast_fail.cpp diff --git a/test/Jamfile b/test/Jamfile new file mode 100644 index 0000000..2a274a9 --- /dev/null +++ b/test/Jamfile @@ -0,0 +1,34 @@ +# Signals library + +# Copyright (C) 2001-2003 Douglas Gregor + +# Permission to copy, use, sell and distribute this software is granted +# provided this copyright notice appears in all copies. Permission to modify +# the code and to distribute modified code is granted provided this copyright +# notice appears in all copies, and a notice that the code was modified is +# included with the copyright notice. This software is provided "as is" +# without express or implied warranty, and with no claim as to its suitability +# for any purpose. + +# For more information, see http://www.boost.org/ + + +# Testing Jamfile autogenerated from XML source +subproject libs/conversion/test ; + +# bring in rules for testing +SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; +include testing.jam ; + +# Make tests run by default. +DEPENDS all : test ; + +{ + test-suite conversion + : [ run implicit_cast.cpp ] + [ compile-fail implicit_cast_fail.cpp ] + [ run ../cast_test.cpp ] + [ run ../lexical_cast_test.cpp ] + ; +} + \ No newline at end of file diff --git a/test/implicit_cast.cpp b/test/implicit_cast.cpp new file mode 100644 index 0000000..39aee56 --- /dev/null +++ b/test/implicit_cast.cpp @@ -0,0 +1,34 @@ +// Copyright David Abrahams 2003. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. + +#include +#include +#include + +using boost::implicit_cast; +using boost::type; + +template +type check_return(T) { return type(); } + +struct foo +{ + foo(char const*) {} + operator long() const { return 0; } +}; + +typedef type long_type; +typedef type foo_type; + +int main() +{ + type x = check_return(boost::implicit_cast(1)); + assert(boost::implicit_cast(1) == 1L); + + type f = check_return(boost::implicit_cast("hello")); + type z = check_return(boost::implicit_cast(foo("hello"))); + return 0; +} diff --git a/test/implicit_cast_fail.cpp b/test/implicit_cast_fail.cpp new file mode 100644 index 0000000..9805256 --- /dev/null +++ b/test/implicit_cast_fail.cpp @@ -0,0 +1,23 @@ +// Copyright David Abrahams 2003. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. + +#include +#include + +#define BOOST_INCLUDE_MAIN +#include + +using boost::implicit_cast; + +struct foo +{ + explicit foo(char const*) {} +}; + +int test_main(int, char*[]) +{ + foo x = implicit_cast("foobar"); +}