Boost logo

Boost :

From: Sid Sacek (ssacek_at_[hidden])
Date: 2008-07-13 00:22:10


Don't be mad.

How about using precompiled headers?

-Sid Sacek

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Steven Watanabe
Sent: Saturday, July 12, 2008 11:57 PM
To: boost_at_[hidden]
Subject: [boost] detecting ODR violations

AMDG

I've been trying to work out a way to cause an explicit error if configuration macros are defined differently in different
translation units. I really wish I could cause a link error, but the best I've been able to come up with so far is a runtime error

// test_odr.hpp
#ifndef TEST_ODR_HPP_INCLUDED
#define TEST_ODR_HPP_INCLUDED

#include <iostream>
#include <cstdlib>

#ifndef SOME_MACRO
#define SOME_MACRO true
#endif

template< bool > struct test_odr
{
    static bool value;
};

template< bool b > bool test_odr< b >::value = SOME_MACRO;

namespace
{
    struct test_odr_impl_t
    {
        test_odr_impl_t()
        {
            if ( test_odr< true >::value != SOME_MACRO )
            {
                std::cerr << "Error: SOME_MACRO defined differently in two translation units.\n";
                std::abort();
            }
        }
    };
    test_odr_impl_t test_odr_impl;
}

#endif

// test_odr1.cpp
#include "test_odr.hpp"
int main() {}

// test_odr2.cpp
#define SOME_MACRO false
#include "test_odr.hpp"

Comments? Any better ideas?

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk