This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] libstdc++/21244


Hi Gaby

>Avoiding any use of unamed enumeration is too drastic a cure for this
>specific issue in the library.  For example, the following is
>perfectly fine
>
>   template<class>
>      struct is_integer { enum { value = 0 }; };
>
>  template<class>
>      struct is_floatiing_point { enum { value = 0 }; };
>
>  template<class T>
>     struct is_arithemtic { 
>        enum { 
>           value = is_integer<T>::value || is_floatiing_point<T>::value
>        };
>     };
>  
>
I agree about your "hyper-panic mode" remark. Actually I was exactly
considering in my mind the last situation. In our current
cpp_type_traits we have this specific code, exploiting your nice traitor:

  template<class _Sp, class _Tp>
    struct __traitor
    {
      enum { __value = _Sp::__value || _Tp::__value };
      typedef typename __truth_type<__value>::__type __type;
    };

  template<typename _Tp>
    struct __is_arithmetic
    : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
    { };

Is this 100% safe even if the user (contra any good C++ programming book
advice) overloads operator|| like, in c++/19404, operator/?!?

For reference, the below is my complete grep, quite a few uses seem
problematic (e.g., in pool_allocator):

./include/bits/cpp_type_traits.h:109:      enum { __value = _Sp::__value
|| _Tp::__value };
./include/bits/cpp_type_traits.h:117:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:124:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:144:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:151:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:161:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:171:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:178:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:185:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:192:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:200:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:208:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:215:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:222:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:229:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:236:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:243:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:250:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:257:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:267:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:275:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:282:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:289:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:299:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:306:      enum { __value = 1 };
./include/bits/cpp_type_traits.h:316:      enum { __value = 0 };
./include/bits/cpp_type_traits.h:324:      enum { __value = 1 };
./include/bits/stl_algo.h:2075:  enum { _S_threshold = 16 };
./include/bits/stl_algo.h:3121:  enum { _S_chunk_size = 7 };
./include/bits/stl_bvector.h:67:  enum _S_word_bit_enum { _S_word_bit =
int(CHAR_BIT * sizeof(_Bit_type)) };
./include/bits/stl_deque.h:417:      enum { _S_initial_map_size = 8 };
./include/debug/formatter.h:371:    enum { __max_parameters = 9 };
./include/debug/formatter.h:379:    enum { _M_indent = 4 } ;
./include/ext/hashtable.h:212:  enum { _S_num_primes = 28 };
./include/ext/mt_allocator.h:60:      enum { _S_align = 8 };
./include/ext/mt_allocator.h:61:      enum { _S_max_bytes = 128 };
./include/ext/mt_allocator.h:62:      enum { _S_min_bin = 8 };
./include/ext/mt_allocator.h:63:      enum { _S_chunk_size = 4096 - 4 *
sizeof(void*) };
./include/ext/mt_allocator.h:64:      enum { _S_max_threads = 4096 };
./include/ext/mt_allocator.h:65:      enum { _S_freelist_headroom = 10 };
./include/ext/pool_allocator.h:81:      enum { _S_align = 8 };
./include/ext/pool_allocator.h:82:      enum { _S_max_bytes = 128 };
./include/ext/pool_allocator.h:83:      enum { _S_free_list_size =
_S_max_bytes / _S_align };
./include/ext/rope:548:    enum { _S_max_rope_depth = 45 };
./include/ext/rope:664:      enum { _S_alloc_granularity = 8 };
./include/ext/rope:1034:      enum { _S_path_cache_len = 4 }; // Must be
<= 9.
./include/ext/rope:1035:      enum { _S_iterator_buf_len = 15 };
./include/ext/rope:1502:      enum { _S_copy_max = 23 };
./include/tr1/array:63:      enum { _S_index = _Nm };
./src/debug.cc:636:     enum { __max_field_len = 16 };

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]