Boost logo

Boost Users :

Subject: [Boost-users] Boost.Test segfault clang++3.3 macports cmake
From: Dave Gomboc (dave_gomboc_at_[hidden])
Date: 2013-07-27 21:00:06


I am getting a segmentation fault when attempting to use Boost.Test. I
suspect that I don't have something set up correctly -- your assistance in
remedying this would be appreciated. I am using clang++-mp-3.3 as
installed by MacPorts on OS X 10.8.4. Here's the crash, which occurs after
Boost.Test reports "*** No errors detected".

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x000000010006f6d6 in boost::unit_test::test_unit::~test_unit ()
(gdb) bt
#0 0x000000010006f6d6 in boost::unit_test::test_unit::~test_unit ()
#1 0x000000010003bb5f in
boost::unit_test::master_test_suite_t::~master_test_suite_t ()
#2 0x000000010003bcdd in boost::unit_test::framework_impl::~framework_impl
()
#3 0x00007fff8f465307 in __cxa_finalize ()
#4 0x00007fff8f466f57 in exit ()
#5 0x00007fff96ddc7e8 in start ()
(gdb)

Here's a somewhat simplified version of what I have:

==== UseBoostUnitTestFramework.hpp ====

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
#pragma clang diagnostic ignored "-Wexit-time-destructors"
#pragma clang diagnostic ignored "-Wextra-semi"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wweak-vtables"
#include <boost/test/unit_test.hpp>
#pragma clang diagnostic pop

==== HaveBoostUnitTestFrameworkDefineMain.cpp ====

#define BOOST_TEST_MODULE All_Tests

#include "UseBoostUnitTestFramework.hpp"

/* commenting out the next 3 lines makes no difference */
namespace boost { namespace unit_test { namespace framework {
master_test_suite_t & master_test_suite();
} } } // namespace boost::unit_test::framework

==== CMakeLists.txt ====

cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)
cmake_policy(VERSION 2.8.10)

project (Foo)

add_definitions(-DBOOST_TEST_DYN_LINK)
add_library (foo SHARED
    Foo1.hpp
    more files...
    UseBoostUnitTestFramework.hpp
    Foo1.cpp
    more files...
)

find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
file(GLOB_RECURSE test_source_files *.unit_tests.cpp)
link_directories(${Boost_LIBRARY_DIRS})
add_executable(all_tests
    HaveBoostUnitTestFrameworkDefineMain.cpp ${test_source_files})
target_link_libraries(all_tests
    foo
    ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
)
set(CTEST_OUTPUT_ON_FAILURE TRUE)
enable_testing()
add_test(all_tests all_tests)

set(CMAKE_C_COMPILER "clang-mp-3.3")
set(CMAKE_C_FLAGS "-Weverything --std=c11 -O3 -DNDEBUG")
set(CMAKE_CXX_COMPILER "clang++-mp-3.3")
set(CMAKE_CXX_FLAGS "-ferror-limit=1 --std=c++1y -stdlib=libc++
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -O3
-DNDEBUG")

==== Foo1.hpp ====
(has declarations, but nothing that depends on Boost at all -- nor does any
other non-test file)

==== Foo1.cpp ====
(has definitions, but nothing that depends on Boost at all -- nor does any
other non-test file)

====Foo1.unit_tests.cpp ====

#include "Foo1.hpp"
#include <string>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"

#include "UseBoostUnitTestFramework.hpp"

BOOST_AUTO_TEST_SUITE(Bar1)

BOOST_AUTO_TEST_CASE(foobar1) {
    BOOST_CHECK_EQUAL(std:string("a"), std::string("a"));
}

BOOST_AUTO_TEST_CASE(foobar2) {
    BOOST_CHECK_EQUAL(true, true);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(Bar2)

BOOST_AUTO_TEST_CASE(barfoo1) {
    BOOST_CHECK_EQUAL(1, 1);
}

BOOST_AUTO_TEST_CASE(barfoo2) {
    BOOST_CHECK_EQUAL(0, 0);
}

BOOST_AUTO_TEST_SUITE_END()

#pragma clang diagnostic pop



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