https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66308

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
When the char member is accessed:

struct node_base {
  char c;
};

struct node : node_base {
  long long l;
};

int main()
{
  unsigned char buf[sizeof(node_base)+1];
  node_base* n = (node_base*)(buf+1);
  (void) static_cast<node*>(n)->c;
}

GCC again doesn't complain, but Clang complains about the downcast again and
also an upcast (when accessing the member of the base):

ubb.cc:13:10: runtime error: downcast of misaligned address 0xffedafe3 for type
'node', which requires 4 byte alignment
0xffedafe3: note: pointer points here
 ff  f0 d5 06 08 00 00 00 00  00 00 00 00 73 3b 6f 4a  01 00 00 00 84 b0 ed ff 
8c b0 ed ff 20 69 61
              ^ 
ubb.cc:13:10: runtime error: upcast of misaligned address 0xffedafe3 for type
'node', which requires 4 byte alignment
0xffedafe3: note: pointer points here
 ff  f0 d5 06 08 00 00 00 00  00 00 00 00 73 3b 6f 4a  01 00 00 00 84 b0 ed ff 
8c b0 ed ff 20 69 61
              ^

Reply via email to