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

static_assert for fc unpack of const type #26

Merged
merged 1 commit into from
Apr 12, 2024
Merged

static_assert for fc unpack of const type #26

merged 1 commit into from
Apr 12, 2024

Conversation

heifner
Copy link
Member

@heifner heifner commented Apr 12, 2024

Instead of generating an error at runtime with FC_ASSERT, generate an error at compile time for trying to unpack a const type.

Example error:

/home/heifner/ext/leap/libraries/libfc/include/fc/io/raw.hpp:249:8: error: static assertion failed due to requirement '!std::is_same_v<const eosio::chain::packed_transaction, const eosio::chain::packed_transaction>': can't unpack const type
       static_assert(not std::is_same_v<const T, const T>, "can't unpack const type");
       ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/heifner/ext/leap/plugins/net_plugin/net_plugin.cpp:3195:16: note: in instantiation of function template specialization 'fc::raw::unpack<fc::mb_datastream<1048576>, eosio::chain::packed_transaction>' requested here
      fc::raw::unpack( ds, *ptr );
               ^
1 error generated.

Note non-const already hits:

/home/heifner/ext/leap/libraries/libfc/include/fc/io/raw.hpp:360:58: error: invalid operands to binary expression ('fc::mb_datastream<1048576>' and 'eosio::testitnow')
        static inline void unpack( Stream& s, T& v ) { s >> v; }

@heifner heifner requested review from greg7mdp and linh2931 April 12, 2024 13:38
@heifner heifner merged commit ab66679 into main Apr 12, 2024
36 checks passed
@heifner heifner deleted the unpack-error branch April 12, 2024 18:08
@heifner heifner added the OCI Work exclusive to OCI team label Apr 12, 2024
@ericpassmore
Copy link
Contributor

Note:start
group: IF
category: INTERNALS
summary: Cleaner code, add static_assert for fc unpack of const type.
Note:end

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

Successfully merging this pull request may close these issues.

4 participants