-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed as duplicate of#70139
Closed as duplicate of#70139
Copy link
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicateResolved as duplicatefalse-negativeWarning doesn't fire when it shouldWarning doesn't fire when it should
Description
The following code sample produces no -Waddress-of-packed-member diagnostics on Clang 19:
struct Packed {
int foo;
} __attribute__((packed));
const Packed *get_packed_struct();
void use_const_int_ref(const int &);
void foo() {
use_const_int_ref(get_packed_struct()->foo);
const Packed *p = get_packed_struct();
use_const_int_ref(p->foo);
}
Clang warns about this for pointers: https://godbolt.org/z/nMdEGcc4s which have the same alignment requirements as references.
A reduced version of the 'real-world' code motivating this bug looked something like:
struct Packed {
int foo;
} __attribute__((packed));
const Packed *get_packed_struct();
std::optional<int> foo() {
const Packed *p = get_packed_struct();
// std::optional's ctor takes this as a `const int&`, which requires alignof(int).
// If this function didn't have an implicit conversion to optional, this would work
// fine, since Clang emits IR assuming 1-byte alignment for this load.
return p->foo;
}
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicateResolved as duplicatefalse-negativeWarning doesn't fire when it shouldWarning doesn't fire when it should