Boost logo

Boost Users :

From: Kolya Kosenko (wxkolya_at_[hidden])
Date: 2007-05-27 13:24:57


This bug exists at msvc-6.0 and msvc-7.1 when precompiled headers is
used. It is *not* exits at msvc-8.0 at all. I have no msvc-7.0 so I
suppose it behavior is similar to msvc-7.1.
Also I have following linker error at msvc-6.0 when I have solved
previous problem:
filemain.obj : error LNK2005: "bool boost::test_tools::`anonymous
namespace'::dummy_cond"
(?dummy_cond@?%..\..\boost/test/unit_test_log.hpp1238016409_at_test_tools_at_boost@@3_NA)
already defined in pch.obj

This patches should fix both problems:
==========
--- boost/boost/test/utils/trivial_singleton.hpp 2006-01-01
19:29:38.000000000 +0200
+++ boost/boost/test/utils/trivial_singleton.hpp.patched 2007-05-27
20:00:15.031250000 +0300
@@ -55,6 +55,10 @@
 #define BOOST_TEST_SINGLETON_INST( inst ) \
 static BOOST_JOIN( inst, _t)& inst = BOOST_JOIN (inst, _t)::instance();
 
+#elif BOOST_WORKAROUND(BOOST_MSVC, < 1400)
+#define BOOST_TEST_SINGLETON_INST( inst ) \
+namespace { static BOOST_JOIN( inst, _t)& inst = BOOST_JOIN( inst,
_t)::instance(); }
+
 #else
 
 #define BOOST_TEST_SINGLETON_INST( inst ) \
==========
--- boost/boost/test/test_tools.hpp.orig.bak 2007-02-22
19:57:30.000000000 +0200
+++ boost/boost/test/test_tools.hpp 2007-05-27 18:53:26.718750000 +0300
@@ -259,8 +259,16 @@
 
 typedef unit_test::const_string const_string;
 
+#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
+
+static dummy_cond = false;
+
+#else
+
 namespace { bool dummy_cond = false; }
 
+#endif
+
 namespace tt_detail {
 
 //
**************************************************************************
//
==========

Following command line options and files I have used to write and test
patches.
bjam --toolset=msvc-6.0 --without-python debug threading=multi
link=static runtime-link=shared
bjam --toolset=msvc-7.1 --without-python debug threading=multi
link=static runtime-link=shared
bjam --toolset=msvc-8.0 --without-python debug threading=multi
link=static runtime-link=shared

==========
# Jamfile.v2
cpp-pch pch : stdafx.h ;
exe filemain : filemain.cpp file1.cpp stdafx.cpp pch ;
==========
// stdafx.h
#ifndef STDAFX_H
#define STDAFX_H
#include <boost/test/unit_test.hpp>
#endif
==========
// stdafx.cpp
#include "stdafx.h"
#include <boost/test/included/unit_test.hpp>
==========
// file1.cpp
#include "stdafx.h"
BOOST_AUTO_TEST_CASE( test2 )
{
    BOOST_CHECK( 2 == 3 );
}
==========
// filemain.cpp
#include "stdafx.h"
BOOST_AUTO_TEST_CASE( test1 )
{
    BOOST_CHECK( 2 == 1 );
}
#ifndef BOOST_BUILD_PCH_ENABLED
#error Precompiled headers is not enabled
#endif
::boost::unit_test::test_suite*
init_unit_test_suite( int, char* [] )
{
    return 0;
}
==========

I think it would be nice to include tests for precompiled headers in
regression tests of Boost.Test library.

Thank you!

Gennadiy Rozental wrote:
>> "Kolya" <wxkolya_at_[hidden]> wrote in message
>> news:1f5259800705230242hb812523mc864b34c6d35e145_at_mail.gmail.com...
>> Hi, All!
>>
>> I am using Boost.Test library in my own application and I have included
>> boost/test/unit_test.hpp in many my cpp-files.
>> When I used boost version 1.33.1 all works fine. But in version 1.34 I
>> have following compiler error:
>>
>> file1.obj : error LNK2005: "class unit_test_log_t::boost::unit_test_log_t
>> & boost::unit_test::`anonymous namespace'::unit_test_log"
>> (?unit_test_log@?
>> A0xa35d3712_at_unit_test_at_boost@@3AAVunit_test_log_t_at_23 @A) already defined in
>> file2.obj
>>
>
> Looks liek clear compiler bug. Anounimus namespace is used specifically to
> avoid duplicate symbols.
>
>
>> After including boost/test/unit_test.hpp class unit_test_log has multiple
>> instances.
>> See boost/test/unit_test_log.hpp for details:
>>
>> BOOST_TEST_SINGLETON_INST( unit_test_log )
>>
>> It means that following code will be included in many cpp-files!
>>
>> namespace { unit_test_log_t & inst = unit_test_log_t::instance(); }
>>
>
> Try adding static. Though it's like saying the same twice.
>
> namespace { static unit_test_log_t & inst = unit_test_log_t::instance(); }



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net