rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.18k stars 441 forks source link

Register a class ("mclass") with the custom name ("mymclass") witch contains a raw name ("mclass") causes the type get_name() return a wrong name ("mymymclass") #27

Closed sbalogh closed 7 years ago

sbalogh commented 7 years ago

The patch below solves the problem for me.

diff --git a/src/rttr/detail/type/type_register.cpp b/src/rttr/detail/type/type_register.cpp
index 332fff2..2afc182 100644
--- a/src/rttr/detail/type/type_register.cpp
+++ b/src/rttr/detail/type/type_register.cpp
@@ -440,7 +440,7 @@ void type_register_private::register_custom_name(type& t, string_view custom_nam
     auto tmp_type_list = custom_name_to_id.value_data();
     for (auto& tt : tmp_type_list)
     {
-        if (tt.get_raw_array_type() == t)
+        if (tt.get_raw_array_type() == t && tt != t)
         {
             const auto& orig_name_derived = tt.m_type_data->name;
             custom_name_to_id.erase(orig_name_derived);

type_register.diff.zip

acki-m commented 7 years ago

Can you please give me the registration code, i.e. a test case?

sbalogh commented 7 years ago

Test case code is attached.

main.cpp.zip

acki-m commented 7 years ago

This is the output I get with the latest version:

Name:myshape
Name:circleyour
Name:mypoint2d
Name:mycolor

Seems good to me. Or am I missing something?

sbalogh commented 7 years ago

It is interesting. I get with the git master:

Name:mymyshape
Name:circleyouryour
Name:mymypoint2d
Name:mymycolor

I think this is the "right" behavior, because without the patch in the type_register_private::register_custom_name function the type_data.name firstly is assigned to a new custom name for the given type t (line1). After that in the for loop old raw names are replaced with new custom name for all type including for the given type t with an already updated type_data.name (line2).

acki-m commented 7 years ago

what compiler do you use?

sbalogh commented 7 years ago

I'm using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 on Ubuntu 16.04. I was surprised your output.