| 1 | /*
|
|---|
| 2 | * Compile with: cl -MD -I. -EHsc -O2 tt_failure.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * tt_failure.cpp
|
|---|
| 5 | * .\boost/type_traits/type_with_alignment.hpp(206) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
|
|---|
| 6 | * with
|
|---|
| 7 | * [
|
|---|
| 8 | * x=false
|
|---|
| 9 | * ]
|
|---|
| 10 | * .\boost/type_traits/type_with_alignment.hpp(218) : see reference to class template instantiation 'boost::detail::type_with_alignment_imp<Align>' being compiled
|
|---|
| 11 | * with
|
|---|
| 12 | * [
|
|---|
| 13 | * Align=12
|
|---|
| 14 | * ]
|
|---|
| 15 | * tt_failure.cpp(36) : see reference to class template instantiation 'boost::type_with_alignment<Align>' being compiled
|
|---|
| 16 | * with
|
|---|
| 17 | * [
|
|---|
| 18 | * Align=12
|
|---|
| 19 | * ]
|
|---|
| 20 | * .\boost/type_traits/type_with_alignment.hpp(207) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
|
|---|
| 21 | * with
|
|---|
| 22 | * [
|
|---|
| 23 | * x=false
|
|---|
| 24 | * ]
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #include <boost/function.hpp>
|
|---|
| 28 | #include <boost/type_traits/alignment_of.hpp>
|
|---|
| 29 | #include <boost/type_traits/type_with_alignment.hpp>
|
|---|
| 30 |
|
|---|
| 31 | #ifdef _MSC_VER
|
|---|
| 32 | // This kind of packing is set within MSVC 9.0 headers.
|
|---|
| 33 | // E.g. std::ostream has it.
|
|---|
| 34 | #pragma pack(push,8)
|
|---|
| 35 | #endif /* _MSC_VER */
|
|---|
| 36 |
|
|---|
| 37 | // The issue is gone if Root has no data members
|
|---|
| 38 | struct Root { int a; };
|
|---|
| 39 | // The issue is gone if Root is inherited non-virtually
|
|---|
| 40 | struct A : virtual public Root {};
|
|---|
| 41 |
|
|---|
| 42 | #ifdef _MSC_VER
|
|---|
| 43 | #pragma pack(pop)
|
|---|
| 44 | #endif /* _MSC_VER */
|
|---|
| 45 |
|
|---|
| 46 | // The class gets alignment 12 for some reason
|
|---|
| 47 | // The real-world case that triggered the problem is a user-defined stream class that
|
|---|
| 48 | // derived from std::ostream. Such class could not be used with tools involving type_with_alignment.
|
|---|
| 49 | class my_class :
|
|---|
| 50 | public A
|
|---|
| 51 | {
|
|---|
| 52 | public:
|
|---|
| 53 | // The issue is gone if the type is not a boost::function. The signature doesn't matter.
|
|---|
| 54 | typedef boost::function0< void > function_type;
|
|---|
| 55 | function_type m_function;
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | int main(int, char*[])
|
|---|
| 60 | {
|
|---|
| 61 | boost::type_with_alignment<
|
|---|
| 62 | boost::alignment_of<
|
|---|
| 63 | my_class
|
|---|
| 64 | >::value
|
|---|
| 65 | >::type obj;
|
|---|
| 66 |
|
|---|
| 67 | return static_cast< int >(&obj != NULL);
|
|---|
| 68 | }
|
|---|