Manu343726 / ctti

Compile Time Type Information for C++
MIT License
573 stars 56 forks source link

Bug in unnamed_type_id_t #13

Closed mkurdej closed 8 years ago

mkurdej commented 8 years ago

Lines 146-149 (https://github.com/Manu343726/ctti/blob/master/include/ctti/type_id.hpp#L147) are currently:

            return id_from_name(
                CTTI_TYPE_ID_PRETTY_FUNCTION + CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_BEGIN,
                CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_END - CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_BEGIN - 1
            );

but should be:

            return id_from_name(
                CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION + CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_BEGIN,
                CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_END - CTTI_UNNAMED_TYPE_ID_PRETTY_FUNCTION_BEGIN - 1
            );

Note the first macro missing UNNAMED. So for the moment the hash given by unnamed_typeid() is completely incorrect as instead of hashing e.g. Typename (something), it hashes (example for GCC) ith T = (so. That is, the hashed string starts `8 == strlen("unnamed")` characters to early.

Manu343726 commented 8 years ago

Thanks a lot for noticing this. Hopefully the fix was as simple as you menctioned. Cheers.