epoc32/include/stdapis/boost/static_warning.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
#ifndef BOOST_STATIC_WARNING_HPP
williamr@2
     2
#define BOOST_STATIC_WARNING_HPP
williamr@2
     3
williamr@2
     4
//  (C) Copyright Robert Ramey 2003. Jonathan Turkanis 2004.
williamr@2
     5
// Use, modification and distribution is subject to the Boost Software
williamr@2
     6
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
williamr@2
     7
// MS compatible compilers support #pragma once
williamr@2
     8
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
williamr@2
     9
# pragma once
williamr@2
    10
#endif
williamr@2
    11
williamr@2
    12
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
    13
williamr@2
    14
//  See http://www.boost.org/libs/static_assert for documentation.
williamr@2
    15
williamr@2
    16
/*
williamr@2
    17
 Revision history:
williamr@2
    18
   15 June  2003 - Initial version.
williamr@2
    19
   31 March 2004 - improved diagnostic messages and portability 
williamr@2
    20
                   (Jonathan Turkanis)
williamr@2
    21
   03 April 2004 - works on VC6 at class and namespace scope
williamr@2
    22
                 - ported to DigitalMars
williamr@2
    23
                 - static warnings disabled by default; when enabled,
williamr@2
    24
                   uses pragmas to enable required compiler warnings
williamr@2
    25
                   on MSVC, Intel, Metrowerks and Borland 5.x.
williamr@2
    26
                   (Jonathan Turkanis)
williamr@2
    27
   30 May 2004   - tweaked for msvc 7.1 and gcc 3.3
williamr@2
    28
                 - static warnings ENabled by default; when enabled,
williamr@2
    29
                   (Robert Ramey)
williamr@2
    30
*/
williamr@2
    31
williamr@2
    32
#include <boost/config.hpp>
williamr@2
    33
williamr@2
    34
//
williamr@2
    35
// Implementation
williamr@2
    36
// Makes use of the following warnings:
williamr@2
    37
//  1. GCC prior to 3.3: division by zero.
williamr@2
    38
//  2. BCC 6.0 preview: unreferenced local variable.
williamr@2
    39
//  3. DigitalMars: returning address of local automatic variable.
williamr@2
    40
//  4. VC6: class previously seen as struct (as in 'boost/mpl/print.hpp')
williamr@2
    41
//  5. All others: deletion of pointer to incomplete type.
williamr@2
    42
//
williamr@2
    43
// The trick is to find code which produces warnings containing the name of
williamr@2
    44
// a structure or variable. Details, with same numbering as above:
williamr@2
    45
// 1. static_warning_impl<B>::value is zero iff B is false, so diving an int
williamr@2
    46
//    by this value generates a warning iff B is false.
williamr@2
    47
// 2. static_warning_impl<B>::type has a constructor iff B is true, so an
williamr@2
    48
//    unreferenced variable of this type generates a warning iff B is false.
williamr@2
    49
// 3. static_warning_impl<B>::type overloads operator& to return a dynamically
williamr@2
    50
//    allocated int pointer only is B is true, so  returning the address of an
williamr@2
    51
//    automatic variable of this type generates a warning iff B is fasle.
williamr@2
    52
// 4. static_warning_impl<B>::STATIC_WARNING is decalred as a struct iff B is 
williamr@2
    53
//    false. 
williamr@2
    54
// 5. static_warning_impl<B>::type is incomplete iff B is false, so deleting a
williamr@2
    55
//    pointer to this type generates a warning iff B is false.
williamr@2
    56
//
williamr@2
    57
williamr@2
    58
//------------------Enable selected warnings----------------------------------//
williamr@2
    59
williamr@2
    60
// Enable the warnings relied on by BOOST_STATIC_WARNING, where possible. The 
williamr@2
    61
// only pragma which is absolutely necessary here is for Borland 5.x, since 
williamr@2
    62
// W8073 is disabled by default. If enabling selected warnings is considered 
williamr@2
    63
// unacceptable, this section can be replaced with:
williamr@2
    64
//   #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x600)
williamr@2
    65
//    pragma warn +stu
williamr@2
    66
//   #endif
williamr@2
    67
williamr@2
    68
# if defined(BOOST_MSVC)
williamr@2
    69
#  pragma warning(2:4150) // C4150: deletion of pointer to incomplete type 'type'.
williamr@2
    70
# elif defined(BOOST_INTEL) && (defined(__WIN32__) || defined(WIN32))
williamr@2
    71
#  pragma warning(2:457) // #457: delete of pointer to incomplete class.
williamr@2
    72
# elif defined(__BORLANDC__) && (__BORLANDC__ <= 0x600)
williamr@2
    73
#  pragma warn +stu  // W8073: Undefined structure 'structure'.
williamr@2
    74
# elif defined(__MWERKS__)
williamr@2
    75
#  pragma extended_errorcheck on // Enable 'extended error checking'.
williamr@2
    76
# endif
williamr@2
    77
williamr@2
    78
//------------------Configure-------------------------------------------------//
williamr@2
    79
williamr@2
    80
# if defined(__BORLANDC__) && (__BORLANDC__ >= 0x600)
williamr@2
    81
#  define BOOST_HAS_DESCRIPTIVE_UNREFERENCED_VARIABLE_WARNING
williamr@2
    82
# elif defined(__GNUC__) && !defined(BOOST_INTEL) // && (__GNUC__ * 100 + __GNUC_MINOR__ <= 302)
williamr@2
    83
#  define BOOST_HAS_DESCRIPTIVE_DIVIDE_BY_ZERO_WARNING
williamr@2
    84
# elif defined(__DMC__)
williamr@2
    85
#  define BOOST_HAS_DESCRIPTIVE_RETURNING_ADDRESS_OF_TEMPORARY_WARNING
williamr@2
    86
# elif defined(BOOST_MSVC) // && (BOOST_MSVC < 1300)
williamr@2
    87
#  define BOOST_NO_PREDEFINED_LINE_MACRO
williamr@2
    88
#  pragma warning(disable:4094) // C4094: untagged 'stuct' declared no symbols
williamr@2
    89
#endif
williamr@2
    90
williamr@2
    91
//------------------Helper templates------------------------------------------//
williamr@2
    92
williamr@2
    93
namespace boost {
williamr@2
    94
williamr@2
    95
struct STATIC_WARNING;
williamr@2
    96
williamr@2
    97
template<bool>
williamr@2
    98
struct static_warning_impl;
williamr@2
    99
williamr@2
   100
template<>
williamr@2
   101
struct static_warning_impl<false> {
williamr@2
   102
    enum { value = 0 };
williamr@2
   103
    #if !defined(BOOST_HAS_DESCRIPTIVE_UNREFERENCED_VARIABLE_WARNING) && \
williamr@2
   104
        !defined(BOOST_HAS_DESCRIPTIVE_RETURNING_ADDRESS_OF_TEMPORARY_WARNING)
williamr@2
   105
        typedef boost::STATIC_WARNING type;
williamr@2
   106
    #else
williamr@2
   107
        typedef int type;
williamr@2
   108
    #endif
williamr@2
   109
    #if defined(BOOST_NO_PREDEFINED_LINE_MACRO)
williamr@2
   110
        struct STATIC_WARNING { };
williamr@2
   111
    #endif
williamr@2
   112
};
williamr@2
   113
williamr@2
   114
template<>
williamr@2
   115
struct static_warning_impl<true> {
williamr@2
   116
    enum { value = 1 };
williamr@2
   117
    struct type { type() { } int* operator&() { return new int; } };
williamr@2
   118
    #if defined(BOOST_NO_PREDEFINED_LINE_MACRO)
williamr@2
   119
        class STATIC_WARNING { };
williamr@2
   120
    #endif
williamr@2
   121
};
williamr@2
   122
williamr@2
   123
} // namespace boost
williamr@2
   124
williamr@2
   125
//------------------Definition of BOOST_STATIC_WARNING------------------------//
williamr@2
   126
williamr@2
   127
#if defined(BOOST_HAS_DESCRIPTIVE_UNREFERENCED_VARIABLE_WARNING)
williamr@2
   128
#    define BOOST_STATIC_WARNING_IMPL(B)                   \
williamr@2
   129
     struct BOOST_JOIN(STATIC_WARNING, __LINE__) {         \
williamr@2
   130
       void f() {                                          \
williamr@2
   131
           ::boost::static_warning_impl<(bool)( B )>::type \
williamr@2
   132
           STATIC_WARNING;                                 \
williamr@2
   133
       }                                                   \
williamr@2
   134
     }                                                     \
williamr@2
   135
     /**/
williamr@2
   136
#elif defined(BOOST_HAS_DESCRIPTIVE_RETURNING_ADDRESS_OF_TEMPORARY_WARNING)
williamr@2
   137
#    define BOOST_STATIC_WARNING_IMPL(B)                        \
williamr@2
   138
     struct BOOST_JOIN(STATIC_WARNING, __LINE__) {              \
williamr@2
   139
        int* f() {                                              \
williamr@2
   140
            ::boost::static_warning_impl<(bool)( B )>::type     \
williamr@2
   141
            STATIC_WARNING;                                     \
williamr@2
   142
            return &STATIC_WARNING;                             \
williamr@2
   143
        }                                                       \
williamr@2
   144
     }                                                          \
williamr@2
   145
     /**/
williamr@2
   146
#elif defined(BOOST_HAS_DESCRIPTIVE_DIVIDE_BY_ZERO_WARNING)
williamr@2
   147
#    define BOOST_STATIC_WARNING_IMPL(B)                             \
williamr@2
   148
     struct BOOST_JOIN(STATIC_WARNING, __LINE__) {                   \
williamr@2
   149
         int f() { int STATIC_WARNING = 1;                           \
williamr@2
   150
                   return STATIC_WARNING /                           \
williamr@2
   151
                   boost::static_warning_impl<(bool)( B )>::value; } \
williamr@2
   152
     }                                                               \
williamr@2
   153
     /**/
williamr@2
   154
#elif defined(BOOST_NO_PREDEFINED_LINE_MACRO) 
williamr@2
   155
     // VC6; __LINE__ macro broken when -ZI is used see Q199057, so 
williamr@2
   156
     // non-conforming workaround is used.
williamr@2
   157
#    define BOOST_STATIC_WARNING_IMPL(B)                       \
williamr@2
   158
     struct {                                                  \
williamr@2
   159
        struct S {                                             \
williamr@2
   160
            typedef boost::static_warning_impl<(bool)( B )> f; \
williamr@2
   161
            friend class f::STATIC_WARNING;                    \
williamr@2
   162
        };                                                     \
williamr@2
   163
     }                                                         \
williamr@2
   164
     /**/
williamr@2
   165
#else // Deletion of pointer to incomplete type.
williamr@2
   166
#    define BOOST_STATIC_WARNING_IMPL(B)                     \
williamr@2
   167
     struct BOOST_JOIN(STATIC_WARNING, __LINE__) {           \
williamr@2
   168
         ::boost::static_warning_impl<(bool)( B )>::type* p; \
williamr@2
   169
         void f() { delete p; }                              \
williamr@2
   170
     }                                                       \
williamr@2
   171
     /**/
williamr@2
   172
#endif
williamr@2
   173
williamr@2
   174
#ifndef BOOST_DISABLE_STATIC_WARNINGS
williamr@2
   175
# define BOOST_STATIC_WARNING(B) BOOST_STATIC_WARNING_IMPL(B)
williamr@2
   176
#else // #ifdef BOOST_ENABLE_STATIC_WARNINGS //-------------------------------//
williamr@2
   177
# define BOOST_STATIC_WARNING(B) BOOST_STATIC_WARNING_IMPL(true)
williamr@2
   178
#endif
williamr@2
   179
williamr@2
   180
#endif // BOOST_STATIC_WARNING_HPP