Skip to content

Missing diagnostic for non-standard layout types in offsetof #64619

Closed
@Endilll

Description

@Endilll

Consider the following example (https://godbolt.org/z/o77v1nad9):

struct X1 { int a; };
struct X2 { int b; };
struct Y : X1, X2 {};

static_assert(__builtin_offsetof(Y, b) == 4);
static_assert(offsetof(Y, b) == 4);

static_assert(!std::is_standard_layout_v<Y>, "");

Only GCC warns that non-standard layout type is passed to offsetof, which is conditionally-supported.

<source>:8:34: warning: 'offsetof' within non-standard-layout type 'Y' is conditionally-supported [-Winvalid-offsetof]
    8 | static_assert(__builtin_offsetof(Y, b) == 4);
      |               ~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /opt/compiler-explorer/gcc-trunk-20230811/include/c++/14.0.0/cstddef:50,
                 from <source>:1:
<source>:9:24: warning: 'offsetof' within non-standard-layout type 'Y' is conditionally-supported [-Winvalid-offsetof]
    9 | static_assert(offsetof(Y, b) == 4);
      |                        ^

GCC issues it by default, whereas Clang, MSVC, and EDG doesn't even in pedantic modes (or /W4).

I'm not sure what the solution should be, but I feel like there is a problem to solve.

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partygood first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions