Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61153 - in trunk/libs/config/test: . all
From: john_at_[hidden]
Date: 2010-04-09 08:17:59


Author: johnmaddock
Date: 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
New Revision: 61153
URL: http://svn.boost.org/trac/boost/changeset/61153

Log:
Committed Neils Dekker's new macro tests.
Added:
   trunk/libs/config/test/boost_no_com_value_init.ipp (contents, props changed)
   trunk/libs/config/test/no_com_value_init_fail.cpp (contents, props changed)
   trunk/libs/config/test/no_com_value_init_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/config/test/all/Jamfile.v2 | 5 ++++-
   trunk/libs/config/test/config_info.cpp | 2 ++
   trunk/libs/config/test/config_test.cpp | 12 +++++++++++-
   3 files changed, 17 insertions(+), 2 deletions(-)

Modified: trunk/libs/config/test/all/Jamfile.v2
==============================================================================
--- trunk/libs/config/test/all/Jamfile.v2 (original)
+++ trunk/libs/config/test/all/Jamfile.v2 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -1,7 +1,7 @@
 #
 # Regression test Jamfile for boost configuration setup.
 # *** DO NOT EDIT THIS FILE BY HAND ***
-# This file was automatically generated on Sun Oct 11 13:04:18 2009
+# This file was automatically generated on Fri Apr 09 12:24:54 2010
 # by libs/config/tools/generate.cpp
 # Copyright John Maddock.
 # Use, modification and distribution are subject to the
@@ -265,6 +265,9 @@
 test-suite "BOOST_NO_CHAR32_T" :
 [ run ../no_char32_t_pass.cpp ]
 [ compile-fail ../no_char32_t_fail.cpp ] ;
+test-suite "BOOST_NO_COMPLETE_VALUE_INITIALIZATION" :
+[ run ../no_com_value_init_pass.cpp ]
+[ compile-fail ../no_com_value_init_fail.cpp ] ;
 test-suite "BOOST_NO_CONCEPTS" :
 [ run ../no_concepts_pass.cpp ]
 [ compile-fail ../no_concepts_fail.cpp ] ;

Added: trunk/libs/config/test/boost_no_com_value_init.ipp
==============================================================================
--- (empty file)
+++ trunk/libs/config/test/boost_no_com_value_init.ipp 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -0,0 +1,182 @@
+// (C) Copyright Niels Dekker 2010.
+// Use, modification and distribution are subject to 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)
+
+// See http://www.boost.org/libs/config for most recent version.
+
+// MACRO: BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+// TITLE: No complete value-initialization
+// DESCRIPTION: The C++ compiler does not to have implemented value-initialization completely.
+// See also boost/libs/utility/value_init.htm#compiler_issues
+
+#include <cstdlib>
+#include <iostream>
+
+namespace boost_no_complete_value_initialization
+{
+ enum enum_type { negative_number = -1, magic_number = 42 };
+
+ // A POD struct.
+ struct pod_struct
+ {
+ enum_type e;
+ char c;
+ unsigned char uc;
+ short s;
+ int i;
+ unsigned u;
+ long l;
+ float f;
+ double d;
+ void* p;
+ };
+
+ bool is_zero_initialized(const pod_struct& arg)
+ {
+ return
+ arg.e == 0 &&
+ arg.c == 0 &&
+ arg.uc == 0 &&
+ arg.s == 0 &&
+ arg.i == 0 &&
+ arg.u == 0 &&
+ arg.l == 0 &&
+ arg.f == 0 &&
+ arg.d == 0 &&
+ arg.p == 0;
+ }
+
+ // A class that holds a "magic" enum value.
+ class enum_holder
+ {
+ enum_type m_enum;
+ public:
+
+ enum_holder()
+ :
+ m_enum(magic_number)
+ {
+ }
+
+ bool is_default() const
+ {
+ return m_enum == magic_number;
+ }
+ };
+
+
+ // A class that is not a POD type.
+ class non_pod_class
+ {
+ private:
+ enum_holder m_enum_holder;
+
+ public:
+ int i;
+
+ virtual bool is_value_initialized() const
+ {
+ return m_enum_holder.is_default() && i == 0;
+ }
+
+ virtual ~non_pod_class() {}
+ };
+
+ // The first argument (is_value_initializated) tells whether value initialization
+ // has succeeded.
+ // The second argument tells what expression was evaluated.
+ bool is_true(bool is_value_initializated, const char *const expression)
+ {
+ if ( ! is_value_initializated )
+ {
+ std::cout
+ << "Information: " << expression << " evaluated to false.\n"
+ << std::endl;
+ }
+ return is_value_initializated;
+ }
+
+#define IS_TRUE(value) is_true(value, #value)
+#define IS_ZERO(value) is_true(value == 0, #value " == 0")
+
+ // The default constructor of this class initializes each of its
+ // data members by means of an empty set of parentheses, and checks
+ // whether each of them is value-initialized.
+ class value_initializer
+ {
+ private:
+ enum_holder m_enum_holder;
+ enum_type m_enum;
+ char m_char;
+ unsigned char m_unsigned_char;
+ short m_short;
+ int m_int;
+ unsigned m_unsigned;
+ long m_long;
+ float m_float;
+ double m_double;
+ void* m_ptr;
+ pod_struct m_pod;
+ pod_struct m_pod_array[2];
+ non_pod_class m_non_pod;
+ non_pod_class m_non_pod_array[2];
+
+ public:
+ value_initializer()
+ :
+ m_enum_holder(),
+ m_enum(),
+ m_char(),
+ m_unsigned_char(),
+ m_short(),
+ m_int(),
+ m_unsigned(),
+ m_long(),
+ m_float(),
+ m_double(),
+ m_ptr(),
+ m_pod(),
+ m_pod_array(),
+ m_non_pod(),
+ m_non_pod_array()
+ {
+ }
+
+ // Returns the number of failures.
+ unsigned check() const
+ {
+ return
+ (IS_TRUE( m_enum_holder.is_default() ) ? 0 : 1) +
+ (IS_ZERO(m_enum) ? 0 : 1) +
+ (IS_ZERO(m_char) ? 0 : 1) +
+ (IS_ZERO(m_unsigned_char) ? 0 : 1) +
+ (IS_ZERO(m_short) ? 0 : 1) +
+ (IS_ZERO(m_int) ? 0 : 1) +
+ (IS_ZERO(m_unsigned) ? 0 : 1) +
+ (IS_ZERO(m_long) ? 0 : 1) +
+ (IS_ZERO(m_float) ? 0 : 1) +
+ (IS_ZERO(m_double) ? 0 : 1) +
+ (IS_ZERO(m_ptr) ? 0 : 1) +
+ (IS_TRUE( is_zero_initialized(m_pod) ) ? 0 : 1) +
+ (IS_TRUE( m_non_pod.is_value_initialized() ) ? 0 : 1) +
+ (IS_TRUE( is_zero_initialized(m_pod_array[0])
+ && is_zero_initialized(m_pod_array[1]) ) ? 0 : 1) +
+ (IS_TRUE( m_non_pod_array[0].is_value_initialized()
+ && m_non_pod_array[1].is_value_initialized() ) ? 0 : 1);
+
+ }
+ };
+
+ int test()
+ {
+ // Check both value-initialization on the stack and on the heap:
+ const unsigned num_failures_on_stack = value_initializer().check();
+ const value_initializer* const ptr = new value_initializer();
+ const unsigned num_failures_on_heap = ptr->check();
+ delete ptr;
+ return static_cast<int>(num_failures_on_stack + num_failures_on_heap);
+ }
+
+} // End of namespace.
+

Modified: trunk/libs/config/test/config_info.cpp
==============================================================================
--- trunk/libs/config/test/config_info.cpp (original)
+++ trunk/libs/config/test/config_info.cpp 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -985,6 +985,7 @@
    PRINT_MACRO(BOOST_NO_AUTO_PTR);
    PRINT_MACRO(BOOST_NO_CHAR16_T);
    PRINT_MACRO(BOOST_NO_CHAR32_T);
+ PRINT_MACRO(BOOST_NO_COMPLETE_VALUE_INITIALIZATION);
    PRINT_MACRO(BOOST_NO_CONCEPTS);
    PRINT_MACRO(BOOST_NO_CONSTEXPR);
    PRINT_MACRO(BOOST_NO_CTYPE_FUNCTIONS);
@@ -1080,6 +1081,7 @@
 
 
 
+
    // END GENERATED BLOCK
 
    PRINT_MACRO(BOOST_INTEL);

Modified: trunk/libs/config/test/config_test.cpp
==============================================================================
--- trunk/libs/config/test/config_test.cpp (original)
+++ trunk/libs/config/test/config_test.cpp 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -1,4 +1,4 @@
-// This file was automatically generated on Sun Oct 11 13:04:18 2009
+// This file was automatically generated on Fri Apr 09 12:24:54 2010
 // by libs/config/tools/generate.cpp
 // Copyright John Maddock 2002-4.
 // Use, modification and distribution are subject to the
@@ -172,6 +172,11 @@
 #else
 namespace boost_no_char32_t = empty_boost;
 #endif
+#ifndef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+#include "boost_no_com_value_init.ipp"
+#else
+namespace boost_no_complete_value_initialization = empty_boost;
+#endif
 #ifndef BOOST_NO_CONCEPTS
 #include "boost_no_concepts.ipp"
 #else
@@ -1251,6 +1256,11 @@
       std::cerr << "Failed test for BOOST_NO_CHAR32_T at: " << __FILE__ << ":" << __LINE__ << std::endl;
       ++error_count;
    }
+ if(0 != boost_no_complete_value_initialization::test())
+ {
+ std::cerr << "Failed test for BOOST_NO_COMPLETE_VALUE_INITIALIZATION at: " << __FILE__ << ":" << __LINE__ << std::endl;
+ ++error_count;
+ }
    if(0 != boost_no_concepts::test())
    {
       std::cerr << "Failed test for BOOST_NO_CONCEPTS at: " << __FILE__ << ":" << __LINE__ << std::endl;

Added: trunk/libs/config/test/no_com_value_init_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/config/test/no_com_value_init_fail.cpp 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -0,0 +1,37 @@
+// This file was automatically generated on Fri Apr 09 12:24:53 2010
+// by libs/config/tools/generate.cpp
+// Copyright John Maddock 2002-4.
+// Use, modification and distribution are subject to 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)
+
+// See http://www.boost.org/libs/config for the most recent version.//
+// Revision $Id: generate.cpp 49281 2008-10-11 15:40:44Z johnmaddock $
+//
+
+
+// Test file for macro BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+// This file should not compile, if it does then
+// BOOST_NO_COMPLETE_VALUE_INITIALIZATION should not be defined.
+// See file boost_no_com_value_init.ipp for details
+
+// Must not have BOOST_ASSERT_CONFIG set; it defeats
+// the objective of this file:
+#ifdef BOOST_ASSERT_CONFIG
+# undef BOOST_ASSERT_CONFIG
+#endif
+
+#include <boost/config.hpp>
+#include "test.hpp"
+
+#ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+#include "boost_no_com_value_init.ipp"
+#else
+#error "this file should not compile"
+#endif
+
+int main( int, char *[] )
+{
+ return boost_no_complete_value_initialization::test();
+}
+

Added: trunk/libs/config/test/no_com_value_init_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/config/test/no_com_value_init_pass.cpp 2010-04-09 08:17:57 EDT (Fri, 09 Apr 2010)
@@ -0,0 +1,37 @@
+// This file was automatically generated on Fri Apr 09 12:24:53 2010
+// by libs/config/tools/generate.cpp
+// Copyright John Maddock 2002-4.
+// Use, modification and distribution are subject to 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)
+
+// See http://www.boost.org/libs/config for the most recent version.//
+// Revision $Id: generate.cpp 49281 2008-10-11 15:40:44Z johnmaddock $
+//
+
+
+// Test file for macro BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+// This file should compile, if it does not then
+// BOOST_NO_COMPLETE_VALUE_INITIALIZATION should be defined.
+// See file boost_no_com_value_init.ipp for details
+
+// Must not have BOOST_ASSERT_CONFIG set; it defeats
+// the objective of this file:
+#ifdef BOOST_ASSERT_CONFIG
+# undef BOOST_ASSERT_CONFIG
+#endif
+
+#include <boost/config.hpp>
+#include "test.hpp"
+
+#ifndef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
+#include "boost_no_com_value_init.ipp"
+#else
+namespace boost_no_complete_value_initialization = empty_boost;
+#endif
+
+int main( int, char *[] )
+{
+ return boost_no_complete_value_initialization::test();
+}
+


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