Error compilar YAML-CPP en Rad Studio 2010
-
24-09-2019 - |
Pregunta
No puedo compilar yaml-cpp
en Rad Studio 2010. Tengo un error en nodeutil.h
template <typename T, typename U>
struct is_same_type {
enum { value = false };
};
template <typename T>
struct is_same_type<T, T> {
enum { value = true };
};
template <typename T, bool check>
struct is_index_type_with_check {
enum { value = false };
};
template <> struct is_index_type_with_check<std::size_t, false>
{ enum { value = true }; }; // line 24
#define MAKE_INDEX_TYPE(Type) \
template <> struct is_index_type_with_check<Type, is_same_type<Type, std::size_t>::value> { enum { value = true }; }
MAKE_INDEX_TYPE(int);
MAKE_INDEX_TYPE(unsigned); // line 30
MAKE_INDEX_TYPE(short);
MAKE_INDEX_TYPE(unsigned short);
MAKE_INDEX_TYPE(long);
MAKE_INDEX_TYPE(unsigned long);
#undef MAKE_INDEX_TYPE
Impresión del compilador:
[BCC32 Error] nodeutil.h(30): E2238 Multiple declaration for 'is_index_type_with_check<unsigned int,0>'
[BCC32 Error] nodeutil.h(24): E2344 Earlier declaration of 'is_index_type_with_check<unsigned int,0>'
Creo que todo es correcto: en la línea 24 tengo
is_index_type_with_check<std::size_t, false>
,
En la línea 30 tengo
is_index_type_with_check<unsigned, true>
.
Dos tipos diferentes.
Pero si cambio la línea 24 como a continuación, Rad Studio puede compilar yaml-cpp
template <> struct is_index_type_with_check<std::size_t, true> { enum { value = true }; }; // false -> true
¡¿Por qué?! En la línea 24 obtuve
is_index_type_with_check<std::size_t, true>
y en la línea 30
is_index_type_with_check<unsigned, true>
Dos de tipo idénticamente. Pero todo funciona en Rad Studio y no en MS VS 2008 Express.
Solución
Probando su código con CodeBlocks, los problemas mostraron exactamente viceversa. Esto significa que mi código se compila con
template <> struct is_index_type_with_check<std::size_t, false>
y falla con
template <> struct is_index_type_with_check<std::size_t, true>
en la línea 24.
El problema parece ser, qué tipos de compiladores piensan que son los mismos y que son diferentes. Este problema se propaga en diferentes fases del proceso de compilación. Mire nuevamente el error de su compilador. Los argumentos de la plantilla de is_index_type_with_check
son los mismos para ambos std::size_t
y unsigned
. Eso significa que tu compilador pensó que std::size_t
y unsigned
son diferentes tipos para la deducción de argumentos de plantilla (is_same_type::value == false
), pero la deducción de tipo más tarde encontrada std::size_t
y unsigned
ser del mismo tipo unsigend int
y se queja con un error.
Entonces, para resumir, no leyó el error de su compilador correctamente - MAKE_INDEX_TYPE(unsigned);
creó un is_index_type_with_check<unsigned int, false>
. Ese tipo chocó con tu template <> struct is_index_type_with_check<std::size_t, false>
y el compilador se quejó.