GitHub
github.com › envoyproxy › envoy › issues › 26973
failed build: defining a type within '__builtin_offsetof' is a Clang extension · Issue #26973 · envoyproxy/envoy
April 26, 2023 - [root@sbc-stage-a0 envoy]# bazel build -c opt --config=clang --verbose_failures envoy INFO: Analyzed target //:envoy (814 packages loaded, 38567 targets configured). INFO: Found 1 target... ERROR: ...
Author sergey-safarov
LLVM
reviews.llvm.org › D133574
⚙ D133574 [C2x] reject type definitions in offsetof
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm made very clear that it is an UB having type definitions with in offsetof. After this patch clang will reject any type definitions in __builtin_offsetof · Fixes https://github.com/llvm/llvm-project/issues/57065
Build fails on Fedora 38 with clang 16 (-Wgnu-offsetof-extensions)
ERROR: /home/user/upb/BUILD:102:11: ... /usr/bin/clang-16 -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -MD -MF ... (remaining 22 arguments skipped) Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging upb/arena.c:177:25: error: defining a type within '__builtin_offsetof' is a Clang ... More on github.com
Old alignof Macro for C89 Broken as C23 Extension
Please consider the following offsetof.c file: ~ $ cat offsetof.c /* * Compiler: ~ $ gcc -v clang version 19.1.4 Target: aarch64-unknown-linux-android24 Thread model: posix InstalledDir: /data/data... More on github.com
Getting weird errors with the usage of offsetof() function
You are not using the offsetof macro correctly. The usage is offsetof (type, member), not offsetof (type, type::member) — it is not a member pointer or anything like that that you're passing but the name of the member. More generally, you can't call something incorrectly and expect it to work just because one implementation happens to accept it and do the right thing. More on reddit.com
Fail to build on Ubuntu 24.10
Issue type Bug Have you reproduced the bug with TensorFlow Nightly? Yes Source source TensorFlow version master Custom code No OS platform and distribution Ubuntu 24.10 Mobile device No response Py... More on github.com
GitHub
github.com › protocolbuffers › protobuf › issues › 13736
Build fails on Fedora 38 with clang 16 (-Wgnu-offsetof-extensions) · Issue #13736 · protocolbuffers/protobuf
May 11, 2023 - ERROR: /home/user/upb/BUILD:102:11: Compiling upb/arena.c failed: (Exit 1): clang-16 failed: error executing command (from target //:upb) /usr/bin/clang-16 -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -MD -MF ... (remaining 22 arguments skipped) Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging upb/arena.c:177:25: error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extens
Published May 11, 2023
Author airlockgithubci
Gentoo
bugs.gentoo.org › show_bug.cgi
919798 – dev-build/bazel-6.2.0 - [clang] external/.../mini_table.c: error: defining a type within _builtin_offsetof is a Clang extension [-Werror,-Wgnu-offsetof-extensi
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo · Gentoo's Bugzilla – Bug 919798 dev-build/bazel-6.2.0 - [clang] external/.../mini_table.c: error: defining a type within _builtin_offsetof is a Clang extension [-Werror,-Wgnu-offsetof-extensi Last modified: ...
The Mail Archive
mail-archive.com › cfe-commits@lists.llvm.org › msg421593.html
[clang] [Clang] [Sema] No longer diagnose type definitions in `offsetof` in C23 mode (PR #84169)
+ * + * Additionally, GCC and Clang both support it as an extension in pre-C23 + * mode. */ - (void)__builtin_offsetof(struct S { int a; }, a); /* expected-warning{{defining a type within '__builtin_offsetof' is a Clang extension}} */ + (void)__builtin_offsetof(struct S { int a; }, a); /* pre-c23-warning{{defining a type within '__builtin_offsetof' is a C23 extension}} */ } /* WG14 DR499: yes >From ff3d00b63fcb8cf1d336b45a58771f780efaac31 Mon Sep 17 00:00:00 2001 From: Sirraide <aeternalm...@gmail.com> Date: Wed, 6 Mar 2024 14:53:05 +0100 Subject: [PATCH 2/2] [Clang] Update release notes --- c
GitHub
github.com › llvm › llvm-project › issues › 120357
Old alignof Macro for C89 Broken as C23 Extension · Issue #120357 · llvm/llvm-project
December 18, 2024 - ~ $ cat offsetof.c /* * Compiler: ~ $ gcc -v clang version 19.1.4 Target: aarch64-unknown-linux-android24 Thread model: posix InstalledDir: /data/data/com.termux/files/usr/bin * Error: ~ $ gcc -ansi -pedantic -Wall -Wextra -Werror -o offsetof offsetof.c 2>&1 offsetof.c:27:21: error: defining a type within 'offsetof' is a C23 extension [-Werror,-Wc23-extensions] 27 | return offsetof(struct { char c; }, c); | ^~~~~~ /data/data/com.termux/files/usr/lib/clang/19/include/__stddef_offsetof.h:16:43: note: expanded from macro 'offsetof' 16 | #define offsetof(t, d) __builtin_offsetof(t, d) | ^ 1 error generated.
Author Sha0
Reddit
reddit.com › r/cpp_questions › getting weird errors with the usage of offsetof() function
r/cpp_questions on Reddit: Getting weird errors with the usage of offsetof() function
August 12, 2018 -
At some point in my code (while mapping the OpenGL buffer) I have used offsetof() to specify the byte offset values:
glVertexAttribPointer(SHADER_VERTEX_LOCATION, 3, GL_FLOAT, GL_FALSE, VERTEX_SIZE, (const GLvoid *) (offsetof(VertexData, VertexData::vertex))));
The above code runs fine through GCC on both Linux and Windows, but it shows errors with Clang on Mac.
The errors I am getting are such:
expected ')'
...VERTEX_SIZE, (const GLvoid *) (offsetof(VertexData, VertexData::vertex))));
^
to match this '('
...3, GL_FLOAT, GL_FALSE, VERTEX_SIZE, (const GLvoid *) (offsetof(VertexData, VertexData::vertex))));
^
expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
^I found out that offsetof() has compiler dependent implementations, which could mean that Clang is messing something up.
EDIT:
Okay, I am adding an example here:
#include <iostream>
#include <cstdef>
struct VertexData
{
int a;
int b;
int c;
};
int main()
{
std::cout << offsetof(VertexData, VertexData::a) << std::endl;
}This is working inside Visual Studio, but not in VS Code.
I guess this might be because of how offsetof() has been defined in cstddef.
I found something like this:
#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
#ifdef __cplusplus
/* This line is active in Visual Studio on Windows */
// So far this definition is working correctly with the same sort of use
#define offsetof(s,m) ((::size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m)))
#else
#define offsetof(s,m) ((size_t)&(((s*)0)->m))
#endif
#else
/* My Mac system uses this definition, which is currently throwing a compilation error */
#define offsetof(s,m) __builtin_offsetof(s,m)
#endif Top answer 1 of 4
4
You are not using the offsetof macro correctly. The usage is offsetof (type, member), not offsetof (type, type::member) — it is not a member pointer or anything like that that you're passing but the name of the member. More generally, you can't call something incorrectly and expect it to work just because one implementation happens to accept it and do the right thing.
2 of 4
2
Have you tried removing the class prefix? offsetof(VertexData, vertex)
Clang
clang.llvm.org › docs › LanguageExtensions.html
Clang Language Extensions — Clang 23.0.0git documentation
For example, __has_constexpr_builtin is used in libcxx’s implementation of the <cmath> header file to conditionally make a function constexpr whenever the constant evaluation of the corresponding builtin (for example, std::fmax calls __builtin_fmax) is supported in Clang.
GitHub
github.com › tensorflow › tensorflow › issues › 90459
Fail to build on Ubuntu 24.10 · Issue #90459 · tensorflow/tensorflow
April 2, 2025 - (remaining 43 arguments skipped) external/upb/upb/upb.c:192:10: error: defining a type within 'offsetof' is a C23 extension [-Werror,-Wc23-extensions] 192 | n &= ~(upb_alignof(upb_arena) - 1); | ^~~~~~~~~~~~~~~~~~~~~~ external/upb/upb/upb.c:183:37: note: expanded from macro 'upb_alignof' 183 | #define upb_alignof(type) offsetof (struct { char c; type member; }, member) | ^~~~~~ /usr/lib/llvm-19/lib/clang/19/include/__stddef_offsetof.h:16:43: note: expanded from macro 'offsetof' 16 | #define offsetof(t, d) __builtin_offsetof(t, d) | ^ 1 error generated.
Author drhaozhong
Stack Overflow
stackoverflow.com › questions › 79241305 › tensorflow-error-defining-a-type-within-offsetof-is-a-clang-extension-werro
ios - TensorFlow error: defining a type within 'offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions] - Stack Overflow
ERROR: /private/var/tmp/_bazel_tonmoy/d1033cf820cfe9e8569d67cf059cb6df/external/upb/BUILD:57:11: Compiling upb/upb.c [for tool] failed: (Exit 1): wrapped_clang failed: error executing command (from target @upb//:upb) external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 -DNDEBUG '-DNS_BLOCK_ASSERTIONS=1' ... (remaining 32 arguments skipped) external/upb/upb/upb.c:192:10: error: defining a type within 'offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions] 192 | n &= ~(up
FreeBSD
bugs.freebsd.org › bugzilla › show_bug.cgi
273551 – devel/bazel5: fails on 15.0-CURRENT
FreeBSD Bugzilla – Bug 273551 devel/bazel5: fails on 15.0-CURRENT Last modified: 2025-05-08 16:50:11 UTC · New · Browse · Search · Reports · Help · New Account · Log In · Forgot Password · Format For Printing
GNU
gcc.gnu.org › bugzilla › show_bug.cgi
109398 – libiberty/sha1.c:234:11: warning: defining a type within 'offsetof' is a Clang extension [-Wgnu-offsetof-extensions]
February 3, 2024 - GCC Bugzilla – Bug 109398 libiberty/sha1.c:234:11: warning: defining a type within 'offsetof' is a Clang extension [-Wgnu-offsetof-extensions] Last modified: 2024-03-02 08:17:37 UTC
GitHub
github.com › jax-ml › jax › pull › 25543
Enable --config=clang only on newer Clang versions by copybara-service[bot] · Pull Request #25543 · jax-ml/jax
These flags disable Clang extensions that do things such as reject type definitions within offsetof or reject unknown arguments which does not seem to be needed on versions older than Clang 16 Also, fix a syntax error Fixes #25530 PiperOrigin-RevId: 707118731
Author jax-ml
GitHub
github.com › llvm › llvm-project › issues › 83658
Type definitions should be allowed inside of the offsetof type · Issue #83658 · llvm/llvm-project
March 2, 2024 - Clang does not accept type definitions inside of the type provided to offsetof. However, I don't see any wording which forbids this. Here is an example program (Clang 16 and newer don't seem to accept this): #include int main(v...
Author Halalaluyafail3
The Mail Archive
mail-archive.com › cfe-commits@lists.llvm.org › msg316837.html
[clang] e7300e7 - Diagnose extensions in 'offsetof'
January 18, 2023 - + +**Syntax**: + +.. code-block:: c++ + + __builtin_offsetof(type-name, member-designator) + +**Example of Use**: + +.. code-block:: c++ + + struct S { + char c; + int i; + struct T { + float f[2]; + } t; + }; + + const int offset_to_i = __builtin_offsetof(struct S, i); + const int ext1 = __builtin_offsetof(struct U { int i; }, i); // C extension + const int ext2 = __builtin_offsetof(struct S, t.f[1]); // C & C++ extension + +**Description**: + +This builtin is usable in an integer constant expression which returns a value +of type ``size_t``. The value returned is the offset in bytes to the subobject +designated by the member-designator from the beginning of an object of type +``type-name``. Clang extends the required standard functionality in a few ways: + +* In C language modes, the first argument may be the definition of a new type.
Wikipedia
en.wikipedia.org › wiki › Offsetof
offsetof - Wikipedia
October 29, 2025 - #define offsetof(st, m) \ __builtin_offsetof(st, m)
GitHub
github.com › ponylang › ponyc › issues › 2271
Unable to build ponyc on OSX due to type specifier missing error for offsetof in actor.c · Issue #2271 · ponylang/ponyc
October 11, 2017 - actor.c src/libponyrt/actor/actor.c:20:16: error: expected ')' static_assert((offsetof(pony_actor_t, gc) + sizeof(gc_t)) == ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stddef.h:120:24: note: expanded from macro 'offsetof' #define offsetof(t, d) __builtin_offsetof(t, d) ^ src/libponyrt/actor/actor.c:20:15: note: to match this '(' static_assert((offsetof(pony_actor_t, gc) + sizeof(gc_t)) == ^ src/libponyrt/actor/actor.c:20:16: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] static_assert((offsetof(p
Stack Overflow
stackoverflow.com › questions › 49206519 › not-able-to-use-offsetof-with-clang-compiler-using-libc-and-c14
c++ - Not able to use offsetof with clang compiler using libc++ and C++14 - Stack Overflow
March 10, 2018 - @S.M. It is the same implementation in both /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h and /usr/lib/llvm-3.9/lib/clang/3.9.1/include/stddef.h. The definition of the macro is given as: #define offsetof(t, d) __builtin_offsetof(t, d)