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

Compile error with structures containing bitfields #159

Open
loboernesto86 opened this issue Jul 23, 2024 · 1 comment
Open

Compile error with structures containing bitfields #159

loboernesto86 opened this issue Jul 23, 2024 · 1 comment

Comments

@loboernesto86
Copy link

Expected Behavior

No compilation error

Current Behavior

Structures containing bitfields give the compile errors below, packing seems to make no difference (was not expecting it to make any difference anyway)

...include\rfl\internal\bind_to_tuple.hpp(73,1): error C2664: 'std::tuple<uint8_t &,uint8_t &,uint8_t &,uint8_t &,uint64_t &> std::tie<uint8_t,uint8_t,uint8_t,uint8_t,uint64_t>(uint8_t &,uint8_t &,uint8_t &,uint8_t &,uint64_t &) noexcept': cannot convert argument 1 from 'uint8_t' to 'uint8_t &'
...include\rfl\internal\no_duplicate_field_names.hpp(24,19): error C2338: static_assert failed: 'Duplicate field names are not allowed in either named tuples or Literals.'

How to Reproduce

main.cpp


#include <iostream>
#include "rfl.hpp"
#include "Rfl/json.hpp"


#pragma pack(push,1)
struct DummyBitfieldPacked {
    uint8_t power_on : 1;    
    uint8_t error : 1;       
    uint8_t data_ready : 1;  
    uint8_t reserved : 5;    
    uint64_t data;           
};
#pragma pack(pop)

struct DummyBitfieldUnpacked {
    uint8_t power_on : 1;    
    uint8_t error : 1;       
    uint8_t data_ready : 1;  
    uint8_t reserved : 5;    
    uint64_t data;           
};

struct Dummy {
    bool power_on;   
    bool error;      
    bool data_ready; 
    uint8_t reserved;
    uint64_t data;           
};


int main(){    

    std::string json_string;

    //Errors  C2664 & C2338 
    // const DummyBitfieldPacked dummy_bitfields_packed = { 1, 0, 1, 0, 0x1234567890ABCDEF };
    //json_string = rfl::json::write(dummy_bitfields_packed);
    //std::cout << json_string << std::endl;

    //Errors C2664 & C2338 
    //const DummyBitfieldUnpacked dummy_bitfields_unpacked = { 1, 0, 1, 0, 0x1234567890ABCDEF };
    //json_string = rfl::json::write(dummy_bitfields_unpacked);
    //std::cout << json_string << std::endl;

    const Dummy dummy = {1, 0, 1, 0, 0x1234567890ABCDEF};
    json_string = rfl::json::write(dummy);
    std::cout << json_string << std::endl;

    std::cout << "done";
}

Context (Environment)

Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.10.1
/std:c++20
Windows 11

@liuzicheng1987
Copy link
Contributor

Thanks for the detailed issue. I will take a look!

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

No branches or pull requests

2 participants