Skip to content

clang: Invalid address-of-packed-member warning #144729

@jstengleingithub

Description

@jstengleingithub

https://godbolt.org/z/vKxY544zz

typedef struct __attribute__ ((packed)) {
    char a;
    int element;
} packed_struct_type;

void somefunc (void *a, int b)
{
}

int main (int argc, char **argv)
{
    packed_struct_type packed_struct;

    somefunc(&packed_struct.element, ({3;}));
    somefunc(&packed_struct.element, 3);
} 

diagnostic:

<source>:14:15: warning: taking address of packed member 'element' of class or structure 'packed_struct_type' may result in an unaligned pointer value [-Waddress-of-packed-member]
   14 |     somefunc(&packed_struct.element, ({3;}));
      |  

See an invalid address-of-packed-member warning here. Passing the pointer to a void* parameter should not cause the warning to show, however see the warning in the case of the statement expression in the function call on line 14.

Activity

added
clangClang issues not falling into any other category
on Jun 18, 2025
added
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
and removed
clangClang issues not falling into any other category
on Jun 18, 2025
added 2 commits that reference this issue on Jul 21, 2025
caaca9f
abe802b
added a commit that references this issue on Aug 14, 2025
9d1dd9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      clang: Invalid address-of-packed-member warning · Issue #144729 · llvm/llvm-project