Compare commits

..

15 Commits

Author SHA1 Message Date
Jonathan Turkanis
038df9ba32 Branch for Iostreams development
[SVN r42144]
2007-12-18 20:08:11 +00:00
Niels Dekker
01274cf6ac value_init.hpp now no longer distinguished between workaround and non-workaround, because many compilers don't do value-initialization well. Fixed copy construction and assignment -- discussed with Fernando Cacciola
[SVN r41942]
2007-12-09 22:49:58 +00:00
Niels Dekker
8080673977 Added value_init tests if a copy function of T is called when value_initialized<T> is copied -- a case I hadn't thought of before...
[SVN r41919]
2007-12-09 11:53:08 +00:00
Niels Dekker
a470b591fb Added value_init test for an value_initialized<T> object allocated on the heap.
[SVN r41667]
2007-12-03 21:41:59 +00:00
Niels Dekker
e1a63495b6 Added missing #include to value_init_test.cpp. (My mistake!)
[SVN r41648]
2007-12-03 18:20:19 +00:00
Niels Dekker
7300ac83f1 Added value_init test for C style array of bytes
[SVN r41647]
2007-12-03 18:14:37 +00:00
Niels Dekker
882d38c2c7 Added value_init tests, based upon GCC bug report by Jonathan Wakely. Added URL to Borland bug report.
[SVN r41529]
2007-12-01 12:14:37 +00:00
Niels Dekker
33041ad664 Added tests for two more struct types to value_init_test -- discussed with Fernando Cacciola
[SVN r41436]
2007-11-28 17:19:37 +00:00
Niels Dekker
6a2aa822f8 Added value_init test for struct as used in MSVC bug report regarding value-initialization.
[SVN r41423]
2007-11-27 21:34:08 +00:00
Niels Dekker
09ab16bfc1 Checked the result of value_init test function, hoping to pinpoint exactly for what particular type T value_initialized<T> might fail, on some platforms
[SVN r41326]
2007-11-24 11:51:03 +00:00
Niels Dekker
ec46e40809 Code refactoring: removed private base classes of value_initialized, as suggested by Fernando Cacciola.
[SVN r41216]
2007-11-18 22:11:57 +00:00
Beman Dawes
b3a971e7e9 Copyright and/or License cleanup
[SVN r40890]
2007-11-07 16:08:09 +00:00
John Maddock
7ddb559887 Fix path to test case.
[SVN r40736]
2007-11-04 12:01:16 +00:00
Peter Dimov
ea8c99b1d5 Added a sentence with a brief explanation of the intended uses of BOOST_VERIFY.
[SVN r40731]
2007-11-03 22:47:17 +00:00
Peter Dimov
56b0846099 BOOST_VERIFY added.
[SVN r40728]
2007-11-03 20:55:22 +00:00
13 changed files with 438 additions and 179 deletions

View File

@@ -145,14 +145,20 @@ objects are is implemented in <a href="../../boost/utility/compare_pointees.hpp"
so direct usage of relational operators with the implied aliasing of shallow semantics so direct usage of relational operators with the implied aliasing of shallow semantics
-as with pointers- should not be used with generic code written for this concept.</p> -as with pointers- should not be used with generic code written for this concept.</p>
<h3>Acknowledgements</h3>
<p>Based on the original concept developed by Augustus Saunders.
<br> <br>
</p>
<HR> <HR>
<TABLE> <TABLE>
<TR valign=top> <TR valign=top>
<TD nowrap>Copyright &copy 2003</TD><TD> <TD nowrap>Copyright &copy 2003</TD><TD>
<A HREF="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</A>, <A HREF="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</A>
based on the original concept developed by Augustus Saunders.
</TD></TR></TABLE> </TD></TR></TABLE>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
</BODY> </BODY>
</HTML> </HTML>

View File

@@ -47,9 +47,15 @@ void assertion_failed(char const * expr, char const * function, char const * fil
<P>As is the case with <STRONG>&lt;cassert&gt;</STRONG>, <STRONG>&lt;boost/assert.hpp&gt;</STRONG> <P>As is the case with <STRONG>&lt;cassert&gt;</STRONG>, <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT</STRONG> can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT</STRONG>
will be redefined each time as specified above.</P> will be redefined each time as specified above.</P>
<p><STRONG>&lt;boost/assert.hpp&gt;</STRONG> also defines the macro <STRONG>BOOST_VERIFY</STRONG>.
It has exactly the same behavior as <STRONG>BOOST_ASSERT</STRONG>, except that
the expression that is passed to <STRONG>BOOST_VERIFY</STRONG> is always
evaluated. This is useful when the asserted expression has desirable side
effects; it can also help suppress warnings about unused variables when the
only use of the variable is inside an assertion.</p>
<p><br> <p><br>
<small>Copyright <20> 2002 by Peter Dimov. Distributed under the Boost Software License, Version <small>Copyright <20> 2002, 2007 by Peter Dimov. Distributed under the Boost Software
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or License, Version 1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
</body> </body>
</html> </html>

View File

@@ -3,7 +3,7 @@
<title>Header </title> <title>Header </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Template" content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot"> <meta name="Template" content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<boostcompressed_pair.hpp> <boostcompressed_pair.hpp>
</head> </head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080"> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080">
@@ -59,17 +59,18 @@ public:
empty type, then assigning to that member will produce memory corruption, empty type, then assigning to that member will produce memory corruption,
unless the empty type has a "do nothing" assignment operator defined. This is unless the empty type has a "do nothing" assignment operator defined. This is
due to a bug in the way VC6 generates implicit assignment operators.</p> due to a bug in the way VC6 generates implicit assignment operators.</p>
<hr> <h3>Acknowledgements</h3>
<p>Revised 08 May 2001</p>
<p><EFBFBD> Copyright boost.org 2000. Permission to copy, use, modify, sell and
distribute this document is granted provided this copyright notice appears in
all copies. This document is provided "as is" without express or implied
warranty, and with no claim as to its suitability for any purpose.</p>
<p>Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and John <p>Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and John
Maddock.</p> Maddock.</p>
<p>Maintained by <a href="mailto:john@johnmaddock.co.uk">John Maddock</a>, the <p>Maintained by <a href="mailto:john@johnmaddock.co.uk">John Maddock</a>, the
latest version of this file can be found at <a href="http://www.boost.org">www.boost.org</a>, latest version of this file can be found at <a href="http://www.boost.org">www.boost.org</a>,
and the boost discussion list at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.</p> and the boost discussion list at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.</p>
<p>&nbsp;</p> <hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->07 November 2007<!--webbot bot="Timestamp" endspan i-checksum="40338" --></p>
<p><EFBFBD> Copyright Beman Dawes, 2000.</p>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
</body> </body>
</html> </html>

View File

@@ -2,6 +2,7 @@
// boost/assert.hpp - BOOST_ASSERT(expr) // boost/assert.hpp - BOOST_ASSERT(expr)
// //
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2007 Peter Dimov
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at
@@ -35,3 +36,15 @@ void assertion_failed(char const * expr, char const * function, char const * fil
# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
# define BOOST_ASSERT(expr) assert(expr) # define BOOST_ASSERT(expr) assert(expr)
#endif #endif
#undef BOOST_VERIFY
#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
# define BOOST_VERIFY(expr) ((void)(expr))
#else
# define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
#endif

View File

@@ -6,161 +6,108 @@
// //
// 21 Ago 2002 (Created) Fernando Cacciola // 21 Ago 2002 (Created) Fernando Cacciola
// 07 Set 2007 (Worked around MSVC++ bug) Fernando Cacciola, Niels Dekker // 07 Set 2007 (Worked around MSVC++ bug) Fernando Cacciola, Niels Dekker
// 16 Nov 2007 (Refactoring: removed private base classes) Fernando Cacciola, Niels Dekker
// 09 Dec 2007 (Worked around various compiler bugs) Fernando Cacciola, Niels Dekker
// //
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#include <boost/detail/select_type.hpp> // Note: The implementation of boost::value_initialized had to deal with the
#include <boost/type_traits/cv_traits.hpp> // fact that various compilers haven't fully implemented value-initialization:
#include <boost/detail/workaround.hpp> // Microsoft Feedback ID 100744 - Value-initialization in new-expression
// Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005-07-28
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
// Microsoft Visual C++ does not correctly support value initialization, as reported by
// Pavel Kuznetsov (MetaCommunications Engineering), 7/28/2005, Feedback ID 100744,
// Feedback Title: Value-initialization in new-expression
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
// The report was closed at 11/14/2006, and its status was set to "Closed (Won't Fix)". // GCC Bug 30111 - Value-initialization of POD base class doesn't initialize members
// Luckily, even in the presence of this compiler bug, boost::value_initialized will still // Reported by Jonathan Wakely, 2006-12-07
// do its job correctly, when using the following workaround: // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111
#define BOOST_UTILITY_VALUE_INIT_WORKAROUND // GCC Bug 33916 - Default constructor fails to initialize array members
#endif // Reported by Michael Elizabeth Chastain, 2007-10-26
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
// Borland Report 51854 - Value-initialization: POD struct should be zero-initialized
// Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-11-09
// http://qc.codegear.com/wc/qcmain.aspx?d=51854
// The constructor of boost::value_initialized<T> works around these issues, by
// clearing the bytes of T, before constructing the T object it contains.
#ifdef BOOST_UTILITY_VALUE_INIT_WORKAROUND
#include <boost/aligned_storage.hpp> #include <boost/aligned_storage.hpp>
#include <boost/detail/select_type.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/type_traits/alignment_of.hpp> #include <boost/type_traits/alignment_of.hpp>
#include <cstring> #include <cstring>
#include <new> #include <new>
namespace boost {
template<class T>
class value_initialized
{
private :
struct wrapper
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
typename
#endif
remove_const<T>::type data;
};
mutable
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
typename
#endif
::boost::aligned_storage<sizeof(wrapper), ::boost::alignment_of<wrapper>::value>::type x;
public :
value_initialized()
{
std::memset(&x, 0, sizeof(x));
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning(push) #pragma warning(push)
#if _MSC_VER >= 1310 #if _MSC_VER >= 1310
// When using MSVC 7.1 or higher, placement new, "new (&x) T()", may trigger warning C4345: // When using MSVC 7.1 or higher, the following placement new expression may trigger warning C4345:
// "behavior change: an object of POD type constructed with an initializer of the form () // "behavior change: an object of POD type constructed with an initializer of the form ()
// will be default-initialized". There is no need to worry about this, though. // will be default-initialized". There is no need to worry about this, though.
#pragma warning(disable: 4345) #pragma warning(disable: 4345)
#endif #endif
#endif #endif
new (&x) wrapper();
namespace boost {
namespace vinit_detail {
template<class T>
class const_T_base
{
protected :
const_T_base()
{
std::memset(&x, 0, sizeof(x));
new (&x) T();
}
~const_T_base()
{
void const * ptr = &x;
static_cast<T*>(ptr)->T::~T();
}
T & get() const
{
void const * ptr = &x;
return *static_cast<T*>(ptr);
}
private :
typename ::boost::aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type x;
} ;
template<class T>
class non_const_T_base
{
protected :
non_const_T_base()
{
std::memset(&x, 0, sizeof(x));
new (&x) T();
}
~non_const_T_base()
{
void * ptr = &x;
static_cast<T*>(ptr)->T::~T();
}
T & get() const
{
void * ptr = &x;
return *static_cast<T*>(ptr);
}
private :
mutable typename ::boost::aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type x;
} ;
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
// Restores the state of warning C4345.
#pragma warning(pop) #pragma warning(pop)
#endif #endif
}
#else value_initialized(value_initialized const & arg)
namespace boost {
namespace vinit_detail {
template<class T>
class const_T_base
{ {
protected : void const * const ptr = &(arg.x);
new (&x) wrapper( *static_cast<wrapper const *>(ptr) );
}
const_T_base() : x() {} value_initialized & operator=(value_initialized const & arg)
T & get() const { return x; } {
T & this_data = this->data();
T const & arg_data = arg.data();
this_data = arg_data;
return *this;
}
~value_initialized()
{
void * const ptr = &x;
static_cast<wrapper *>(ptr)->wrapper::~wrapper();
}
T& data() const
{
void * const ptr = &x;
return static_cast<wrapper *>(ptr)->data;
}
operator T&() const { return this->data(); }
private :
T x ;
} ; } ;
template<class T>
class non_const_T_base
{
protected :
non_const_T_base() : x() {}
T & get() const { return x; }
private :
mutable T x ;
} ;
#endif
template<class T>
struct select_base
{
typedef
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
typename
#endif
::boost::detail::if_true< ::boost::is_const<T>::value >
::template then< const_T_base<T>, non_const_T_base<T> >::type type ;
} ;
} // namespace vinit_detail
template<class T>
class value_initialized : private vinit_detail::select_base<T>::type
{
public :
value_initialized() {}
operator T&() const { return this->get(); }
T& data() const { return this->get(); }
} ;
template<class T> template<class T>
T const& get ( value_initialized<T> const& x ) T const& get ( value_initialized<T> const& x )
@@ -177,4 +124,3 @@ T& get ( value_initialized<T>& x )
#endif #endif

View File

@@ -1,8 +1,7 @@
# Copyright David Abrahams 2003. Permission to copy, use, # Copyright David Abrahams 2003.
# modify, sell and distribute this software is granted provided this
# copyright notice appears in all copies. This software is provided # Distributed under the Boost Software License, Version 1.0.
# "as is" without express or implied warranty, and with no claim as # See http://www.boost.org/LICENSE_1_0.txt
# to its suitability for any purpose.
# For more information, see http://www.boost.org/ # For more information, see http://www.boost.org/
@@ -33,4 +32,6 @@ test-suite utility
[ compile-fail ../value_init_test_fail1.cpp ] [ compile-fail ../value_init_test_fail1.cpp ]
[ compile-fail ../value_init_test_fail2.cpp ] [ compile-fail ../value_init_test_fail2.cpp ]
[ compile-fail ../value_init_test_fail3.cpp ] [ compile-fail ../value_init_test_fail3.cpp ]
[ run ../verify_test.cpp ]
; ;

View File

@@ -183,12 +183,12 @@ void f() {
<p>See <a href="base_from_member.html">separate documentation</a>.</p> <p>See <a href="base_from_member.html">separate documentation</a>.</p>
<hr> <hr>
<p>Revised&nbsp; <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan <p>Revised&nbsp; <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan
-->02 May, 2004<!--webbot bot="Timestamp" endspan i-checksum="38582" -->07 November, 2007<!--webbot bot="Timestamp" endspan i-checksum="39369"
--> -->
</p> </p>
<p>&copy; Copyright boost.org 1999-2003. Permission to copy, use, modify, sell and distribute <p>&copy; Copyright Beman Dawes 1999-2003.</p>
this document is granted provided this copyright notice appears in all copies. <p>Distributed under the Boost Software License, Version 1.0. See
This document is provided &quot;as is&quot; without express or implied <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
warranty, and with no claim as to its suitability for any purpose.</p>
</body> </body>
</html> </html>

View File

@@ -197,21 +197,21 @@ the wrapped object is always performed with the <code>get()</code> idiom:</p>
value_initialized was developed by Fernando Cacciola, with help and value_initialized was developed by Fernando Cacciola, with help and
suggestions from David Abrahams and Darin Adler.<br> suggestions from David Abrahams and Darin Adler.<br>
Special thanks to Bj<42>rn Karlsson who carefully edited and completed this documentation. Special thanks to Bj<42>rn Karlsson who carefully edited and completed this documentation.
<pre>&nbsp;</pre>
<hr>
<p>Revised 19 September 2002</p>
<p>&copy; Copyright boost.org 2002. Permission to copy, use, modify, sell
and distribute this document is granted provided this copyright notice appears
in all copies. This document is provided "as is" without express or implied
warranty, and with no claim as to its suitability for any purpose.</p>
<p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>, <p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>,
the latest version of this file can be found at <a the latest version of this file can be found at <a
href="http://www.boost.org">www.boost.org</a>, and the boost discussion list href="http://www.boost.org">www.boost.org</a>, and the boost discussion list
at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>. at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.
</p> </p>
<hr>
<p>Revised 19 September 2002</p>
<p>&copy; Copyright Fernando Cacciola, 2002.</p>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<br> <br>
<br> <br>

View File

@@ -1,4 +1,4 @@
// (C) 2002, Fernando Luis Cacciola Carballal. // Copyright 2002, Fernando Luis Cacciola Carballal.
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at
@@ -8,10 +8,12 @@
// //
// Initial: 21 Agu 2002 // Initial: 21 Agu 2002
#include <cstring> // For memcmp.
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "boost/utility/value_init.hpp" #include "boost/utility/value_init.hpp"
#include <boost/shared_ptr.hpp>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
@@ -62,6 +64,9 @@ struct NonPOD : NonPODBase
// //
// Sample aggregate POD struct type // Sample aggregate POD struct type
// Some compilers do not correctly value-initialize such a struct, for example:
// Borland C++ Report #51854, "Value-initialization: POD struct should be zero-initialized "
// http://qc.codegear.com/wc/qcmain.aspx?d=51854
// //
struct AggregatePODStruct struct AggregatePODStruct
{ {
@@ -73,10 +78,116 @@ struct AggregatePODStruct
bool operator == ( AggregatePODStruct const& lhs, AggregatePODStruct const& rhs ) bool operator == ( AggregatePODStruct const& lhs, AggregatePODStruct const& rhs )
{ return lhs.f == rhs.f && lhs.c == rhs.c && lhs.i == rhs.i ; } { return lhs.f == rhs.f && lhs.c == rhs.c && lhs.i == rhs.i ; }
//
template<class T> // An aggregate struct that contains an std::string and an int.
void test ( T const& y, T const& z ) // Pavel Kuznetsov (MetaCommunications Engineering) used a struct like
// this to reproduce the Microsoft Visual C++ compiler bug, reported as
// Feedback ID 100744, "Value-initialization in new-expression"
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
//
struct StringAndInt
{ {
std::string s;
int i;
};
bool operator == ( StringAndInt const& lhs, StringAndInt const& rhs )
{ return lhs.s == rhs.s && lhs.i == rhs.i ; }
//
// A struct that has an explicit (user defined) destructor.
// Some compilers do not correctly value-initialize such a struct, for example:
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
//
struct StructWithDestructor
{
int i;
~StructWithDestructor() {}
};
bool operator == ( StructWithDestructor const& lhs, StructWithDestructor const& rhs )
{ return lhs.i == rhs.i ; }
//
// A struct that has a virtual function.
// Some compilers do not correctly value-initialize such a struct either, for example:
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
//
struct StructWithVirtualFunction
{
int i;
virtual void VirtualFunction();
};
void StructWithVirtualFunction::VirtualFunction()
{
}
bool operator == ( StructWithVirtualFunction const& lhs, StructWithVirtualFunction const& rhs )
{ return lhs.i == rhs.i ; }
//
// A struct that is derived from an aggregate POD struct.
// Some compilers do not correctly value-initialize such a struct, for example:
// GCC Bugzilla Bug 30111, "Value-initialization of POD base class doesn't initialize members",
// reported by Jonathan Wakely, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111
//
struct DerivedFromAggregatePODStruct : AggregatePODStruct
{
DerivedFromAggregatePODStruct() : AggregatePODStruct() {}
};
//
// A struct that wraps an aggregate POD struct as data member.
//
struct AggregatePODStructWrapper
{
AggregatePODStructWrapper() : dataMember() {}
AggregatePODStruct dataMember;
};
bool operator == ( AggregatePODStructWrapper const& lhs, AggregatePODStructWrapper const& rhs )
{ return lhs.dataMember == rhs.dataMember ; }
typedef unsigned char ArrayOfBytes[256];
//
// A struct that allows testing whether the appropriate copy functions are called.
//
struct CopyFunctionCallTester
{
bool is_copy_constructed;
bool is_assignment_called;
CopyFunctionCallTester()
: is_copy_constructed(false), is_assignment_called(false) {}
CopyFunctionCallTester(const CopyFunctionCallTester & )
: is_copy_constructed(true), is_assignment_called(false) {}
CopyFunctionCallTester & operator=(const CopyFunctionCallTester & )
{
is_assignment_called = true ;
return *this ;
}
};
//
// This test function tests boost::value_initialized<T> for a specific type T.
// The first argument (y) is assumed have the value of a value-initialized object.
// Returns true on success.
//
template<class T>
bool test ( T const& y, T const& z )
{
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter();
boost::value_initialized<T> x ; boost::value_initialized<T> x ;
BOOST_CHECK ( y == x ) ; BOOST_CHECK ( y == x ) ;
BOOST_CHECK ( y == boost::get(x) ) ; BOOST_CHECK ( y == boost::get(x) ) ;
@@ -91,6 +202,9 @@ void test ( T const& y, T const& z )
x_c_ref = z ; x_c_ref = z ;
BOOST_CHECK ( x_c == z ) ; BOOST_CHECK ( x_c == z ) ;
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
BOOST_CHECK ( y == *ptr ) ;
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
boost::value_initialized<T const> cx ; boost::value_initialized<T const> cx ;
BOOST_CHECK ( y == cx ) ; BOOST_CHECK ( y == cx ) ;
@@ -100,21 +214,71 @@ void test ( T const& y, T const& z )
BOOST_CHECK ( y == cx_c ) ; BOOST_CHECK ( y == cx_c ) ;
BOOST_CHECK ( y == boost::get(cx_c) ) ; BOOST_CHECK ( y == boost::get(cx_c) ) ;
#endif #endif
return boost::minimal_test::errors_counter() == counter_before_test ;
} }
int test_main(int, char **) int test_main(int, char **)
{ {
test( 0,1234 ) ; BOOST_CHECK ( test( 0,1234 ) ) ;
test( 0.0,12.34 ) ; BOOST_CHECK ( test( 0.0,12.34 ) ) ;
test( POD(0,0,0.0), POD('a',1234,56.78) ) ; BOOST_CHECK ( test( POD(0,0,0.0), POD('a',1234,56.78) ) ) ;
test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ; BOOST_CHECK ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;
NonPOD NonPOD_object( std::string("NonPOD_object") ); NonPOD NonPOD_object( std::string("NonPOD_object") );
test<NonPOD *>( 0, &NonPOD_object ) ; BOOST_CHECK ( test<NonPOD *>( 0, &NonPOD_object ) ) ;
AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 }; AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 }; AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct); BOOST_CHECK ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );
StringAndInt stringAndInt0;
StringAndInt stringAndInt1;
stringAndInt0.i = 0;
stringAndInt1.i = 1;
stringAndInt1.s = std::string("1");
BOOST_CHECK ( test(stringAndInt0, stringAndInt1) );
StructWithDestructor structWithDestructor0;
StructWithDestructor structWithDestructor1;
structWithDestructor0.i = 0;
structWithDestructor1.i = 1;
BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) );
StructWithVirtualFunction structWithVirtualFunction0;
StructWithVirtualFunction structWithVirtualFunction1;
structWithVirtualFunction0.i = 0;
structWithVirtualFunction1.i = 1;
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
BOOST_CHECK ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );
AggregatePODStructWrapper aggregatePODStructWrapper0;
AggregatePODStructWrapper aggregatePODStructWrapper1;
aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);
return 0; return 0;
} }
@@ -122,7 +286,3 @@ int test_main(int, char **)
unsigned int expected_failures = 0; unsigned int expected_failures = 0;

View File

@@ -1,4 +1,4 @@
// (C) 2002, Fernando Luis Cacciola Carballal. // Copyright 2002, Fernando Luis Cacciola Carballal.
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// (C) 2002, Fernando Luis Cacciola Carballal. // Copyright 2002, Fernando Luis Cacciola Carballal.
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at

View File

@@ -1,4 +1,4 @@
// (C) 2002, Fernando Luis Cacciola Carballal. // Copyright 2002, Fernando Luis Cacciola Carballal.
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at

126
verify_test.cpp Normal file
View File

@@ -0,0 +1,126 @@
//
// verify_test.cpp - a test for BOOST_VERIFY
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2007 Peter Dimov
//
// 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)
//
#include <boost/detail/lightweight_test.hpp>
#include <boost/assert.hpp>
int f( int & x )
{
return ++x;
}
void test_default()
{
int x = 1;
BOOST_VERIFY( 1 );
BOOST_VERIFY( x == 1 );
BOOST_VERIFY( ++x );
BOOST_VERIFY( f(x) );
BOOST_VERIFY( &x );
BOOST_TEST( x == 3 );
}
#define BOOST_DISABLE_ASSERTS
#include <boost/assert.hpp>
void test_disabled()
{
int x = 1;
BOOST_VERIFY( 1 );
BOOST_VERIFY( x == 1 );
BOOST_VERIFY( ++x );
BOOST_VERIFY( f(x) );
BOOST_VERIFY( &x );
BOOST_TEST( x == 3 );
BOOST_VERIFY( 0 );
BOOST_VERIFY( !x );
BOOST_VERIFY( x == 0 );
BOOST_VERIFY( !++x );
BOOST_VERIFY( !f(x) );
BOOST_TEST( x == 5 );
void * p = 0;
BOOST_VERIFY( p );
}
#undef BOOST_DISABLE_ASSERTS
#define BOOST_ENABLE_ASSERT_HANDLER
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <cstdio>
int handler_invoked = 0;
void boost::assertion_failed(char const * expr, char const * function, char const * file, long line)
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::printf;
#endif
printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line);
++handler_invoked;
}
struct X
{
static bool f()
{
BOOST_VERIFY( 0 );
return false;
}
};
void test_handler()
{
int x = 1;
BOOST_VERIFY( 1 );
BOOST_VERIFY( x == 1 );
BOOST_VERIFY( ++x );
BOOST_VERIFY( f(x) );
BOOST_VERIFY( &x );
BOOST_TEST( x == 3 );
BOOST_VERIFY( 0 );
BOOST_VERIFY( !x );
BOOST_VERIFY( x == 0 );
BOOST_VERIFY( !++x );
BOOST_VERIFY( !f(x) );
BOOST_TEST( x == 5 );
void * p = 0;
BOOST_VERIFY( p );
BOOST_VERIFY( X::f() );
BOOST_TEST( handler_invoked == 8 );
}
#undef BOOST_ENABLE_ASSERT_HANDLER
int main()
{
test_default();
test_disabled();
test_handler();
return boost::report_errors();
}