Opened 4 years ago

#13614 new Bugs

padding related issue on VS2017 with boost::endian

Reported by: imak@… Owned by: Beman Dawes
Milestone: To Be Determined Component: endian
Version: Boost 1.67.0 Severity: Problem
Keywords: Cc:

Description

On Visual Studio 2017 upd3, there seems to be some unexpected padding-related behaviour, shown below. The issue might not necessarily be a library 'bug', but I think it's worth looking at.

Code highlighting:

#include <stdio.h>

#include <boost/endian/arithmetic.hpp>
using namespace boost::endian;

#pragma pack(push, 1)

struct Empty {};

struct T1
{
    big_uint16_t d;
    uint8_t d2;
};

struct T2
{
    uint16_t d;
    uint8_t d2;
};

struct D0: T1 {} x0;          // sizeof(x0) evaluates to 3
struct D1: T1, Empty {} x1;   // sizeof(x1) evaluates to 4  <- i think this should also be 3
struct D2: T2, Empty {} x2;   // sizeof(x2) evaluates to 3

// (uint8_t*)&x1.d2 - (uint8_t*)&x1.d   evaluates to 2 (i.e. big_uint16_t is itself not padded)
//
// - tested with a struct containing a char[2], this did not happen
// - tested on various versions of g++ and clang, but this did not happen either.


#pragma pack(pop)



using namespace std;

int main()
{    
    printf("%zu %zu %zu", sizeof(x0), sizeof(x1), sizeof(x2));
    
    return 0;
}

Change History (0)

Note: See TracTickets for help on using tickets.