Skip to content

[clang][Sema] Fix typo in 'offsetof' diagnostics #133448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
@@ -7031,10 +7031,10 @@ def err_offsetof_incomplete_type : Error<
def err_offsetof_record_type : Error<
"offsetof requires struct, union, or class type, %0 invalid">;
def err_offsetof_array_type : Error<"offsetof requires array type, %0 invalid">;
def ext_offsetof_non_pod_type : ExtWarn<"offset of on non-POD type %0">,
def ext_offsetof_non_pod_type : ExtWarn<"'offsetof' on non-POD type %0">,
InGroup<InvalidOffsetof>;
def ext_offsetof_non_standardlayout_type : ExtWarn<
"offset of on non-standard-layout type %0">, InGroup<InvalidOffsetof>;
"'offsetof' on non-standard-layout type %0">, InGroup<InvalidOffsetof>;
def err_offsetof_bitfield : Error<"cannot compute offset of bit-field %0">;
def err_offsetof_field_of_virtual_base : Error<
"invalid application of 'offsetof' to a field of a virtual base">;
4 changes: 2 additions & 2 deletions clang/test/SemaCXX/ms_struct.cpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ struct B : public A {

static_assert(__builtin_offsetof(B, d) == 12,
"We can't allocate the bitfield into the padding under ms_struct");
// expected-warning@-2 {{offset of on non-standard-layout type 'B'}}
// expected-warning@-2 {{'offsetof' on non-standard-layout type 'B'}}

struct C {
#ifdef TEST_FOR_ERROR
@@ -39,5 +39,5 @@ struct C {

static_assert(__builtin_offsetof(C, n) == 8,
"long long field in ms_struct should be 8-byte aligned");
// expected-warning@-2 {{offset of on non-standard-layout type 'C'}}
// expected-warning@-2 {{'offsetof' on non-standard-layout type 'C'}}

2 changes: 1 addition & 1 deletion clang/test/SemaCXX/offsetof-0x.cpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ struct P {
};

void f() {
int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-standard-layout type 'P'}}
int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{'offsetof' on non-standard-layout type 'P'}}
}

struct StandardLayout {
14 changes: 7 additions & 7 deletions clang/test/SemaCXX/offsetof.cpp
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@ struct P {
};

void f() {
int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-POD type 'P'}}
int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{'offsetof' on non-POD type 'P'}}
}

struct Base { int x; };
struct Derived : Base { int y; };
int o = __builtin_offsetof(Derived, x); // expected-warning{{offset of on non-POD type}}
int o = __builtin_offsetof(Derived, x); // expected-warning{{'offsetof' on non-POD type}}

const int o2 = sizeof(__builtin_offsetof(Derived, x));

@@ -51,9 +51,9 @@ struct Derived2 : public Base1, public Base2 {
int z;
};

int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}}
int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}}
int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; // expected-warning{{offset of on non-POD type 'Derived2'}}
int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; // expected-warning{{'offsetof' on non-POD type 'Derived2'}}
int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; // expected-warning{{'offsetof' on non-POD type 'Derived2'}}
int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; // expected-warning{{'offsetof' on non-POD type 'Derived2'}}

// offsetof referring to anonymous struct in base.
// PR7769
@@ -66,7 +66,7 @@ struct foo {
struct bar : public foo {
};

int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1]; // expected-warning{{offset of on non-POD type 'bar'}}
int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1]; // expected-warning{{'offsetof' on non-POD type 'bar'}}


struct LtoRCheck {
@@ -81,7 +81,7 @@ struct Base {
int Field;
};
struct Derived : virtual Base {
void Fun() { (void)__builtin_offsetof(Derived, Field); } // expected-warning {{offset of on non-POD type}} \
void Fun() { (void)__builtin_offsetof(Derived, Field); } // expected-warning {{'offsetof' on non-POD type}} \
expected-error {{invalid application of 'offsetof' to a field of a virtual base}}
};
}
Loading
Oops, something went wrong.