Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTBR_REST=ON: compile error in hash table of status codes #587

Closed
markus-becker-tridonic-com opened this issue Oct 14, 2020 · 8 comments · Fixed by #590
Closed

OTBR_REST=ON: compile error in hash table of status codes #587

markus-becker-tridonic-com opened this issue Oct 14, 2020 · 8 comments · Fixed by #590
Labels

Comments

@markus-becker-tridonic-com
Copy link
Contributor

Describe the bug

When compiling ot-br-posix on an older OpenWrt toolchain and enabling -DOTBR_REST=ON I am getting the following compile error:

In file included from /usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/hashtable.h:35:0,
                 from /usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/unordered_map:47,
                 from /usr/src/toolchain/feeds/otbr/src/rest/resource.hpp:37,
                 from /usr/src/toolchain/feeds/otbr/src/rest/connection.hpp:41,
                 from /usr/src/toolchain/feeds/otbr/src/rest/rest_web_server.hpp:37,
                 from /usr/src/toolchain/feeds/otbr/src/rest/rest_web_server.cpp:29:
/usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/hashtable_policy.h: In instantiation of 'struct std::__detail::_Hash_code_base<otbr::rest::HttpStatusCode, std::pair<const otbr::rest::HttpStatusCode, std::basic_string<char> >, std::__detail::_Select1st, std::hash<otbr::rest::HttpStatusCode>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>':
/usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/hashtable_policy.h:1402:10:   required from 'struct std::__detail::_Hashtable_base<otbr::rest::HttpStatusCode, std::pair<const otbr::rest::HttpStatusCode, std::basic_string<char> >, std::__detail::_Select1st, std::equal_to<otbr::rest::HttpStatusCode>, std::hash<otbr::rest::HttpStatusCode>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true> >'
/usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/hashtable.h:174:11:   required from 'class std::_Hashtable<otbr::rest::HttpStatusCode, std::pair<const otbr::rest::HttpStatusCode, std::basic_string<char> >, std::allocator<std::pair<const otbr::rest::HttpStatusCode, std::basic_string<char> > >, std::__detail::_Select1st, std::equal_to<otbr::rest::HttpStatusCode>, std::hash<otbr::rest::HttpStatusCode>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >'
/usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/unordered_map.h:100:18:   required from 'class std::unordered_map<otbr::rest::HttpStatusCode, std::basic_string<char> >'
/usr/src/toolchain/feeds/otbr/src/rest/resource.hpp:152:53:   required from here
/usr/src/toolchain/staging_dir/toolchain-arm_cortex-a9_gcc-4.8-linaro_glibc-2.19_eabi/arm-openwrt-linux-gnueabi/include/c++/4.8.3/bits/hashtable_policy.h:1070:12: error: invalid use of incomplete type 'struct std::hash<otbr::rest::HttpStatusCode>'
     struct _Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2,
            ^
compilation terminated due to -Wfatal-errors.

To Reproduce Information to reproduce the behavior, including:

  1. Git commit id: 7a53c4c
  2. IEEE 802.15.4 hardware platform: N/A
  3. Build steps
  4. Network topology: RCP

Expected behavior A clear and concise description of what you expected to happen.

Console/log output If applicable, add console/log output to help explain your problem.

Additional context Add any other context about the problem here.

@markus-becker-tridonic-com markus-becker-tridonic-com changed the title OTBR_REST=ON: OTBR_REST=ON: compile error in hash table of status codes Oct 14, 2020
@wgtdkp
Copy link
Member

wgtdkp commented Oct 14, 2020

@tttttangTH Any ideas?

@jwhui jwhui added the question label Oct 14, 2020
@jwhui
Copy link
Member

jwhui commented Oct 14, 2020

This appears to be a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970

I think the only fixes are:

  1. Avoid use of std::hash.
  2. Use a newer version of gcc.

@markus-becker-tridonic-com
Copy link
Contributor Author

markus-becker-tridonic-com commented Oct 14, 2020

This appears to be a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970

I think the only fixes are:

  1. Avoid use of std::hash.
  2. Use a newer version of gcc.

I was fearing 2, since this is a vendored-OpenWrt toolchain.
Possibly I could include the patch referenced in Bugzilla.

@tttttangTH
Copy link
Contributor

tttttangTH commented Oct 14, 2020

This appears to be a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970

I think the only fixes are:

  1. Avoid use of std::hash.
  2. Use a newer version of gcc.

@tttttangTH Any ideas?

Will fix it soon.

@tttttangTH
Copy link
Contributor

tttttangTH commented Oct 14, 2020

This issue has been fixed in second PR #537 for OTBR-REST, my solution is to specialize std::hash for HttpStatusCode. I'm not sure whether it is a better practice compared to avoiding using std::hash. @wgtdkp

I will now create a PR to fix this.

@wgtdkp
Copy link
Member

wgtdkp commented Oct 14, 2020

This issue has been fixed in second PR #537 for OTBR-REST, my solution is to specialize std::hash for HttpStatusCode. I'm not sure whether it is a better practice compared to avoiding using std::hash. @wgtdkp

I will now create a PR to fix this.

@tttttangTH What about we avoid using a hash map by a static function?

const char *GetHttpStatus(ResponseCode aCode)
{
    switch (aCode)
    {
    case ...:
    
    }
}

Since the number of the response codes is static, we don't really need a map.

@tttttangTH
Copy link
Contributor

This issue has been fixed in second PR #537 for OTBR-REST, my solution is to specialize std::hash for HttpStatusCode. I'm not sure whether it is a better practice compared to avoiding using std::hash. @wgtdkp
I will now create a PR to fix this.

@tttttangTH What about we avoid using a hash map by a static function?

const char *GetHttpStatus(ResponseCode aCode)
{
    switch (aCode)
    {
    case ...:
    
    }
}

Since the number of the response codes is static, we don't really need a map.

Yes, if we need to define another hash function for this, it does bring more complexity compared to just use switch.

@markus-becker-tridonic-com
Copy link
Contributor Author

Confirmed that it works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants