[PATCH] D133574: [C2x] reject type definitions in offsetof
YingChi Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 23 07:07:09 PDT 2022
inclyc added a comment.
Emm, is it necessary to add a `LangOpts` check so that this change only applies to c2x? If clang was invoked without `-std=c2x`, should we just accept `offsetof` with definitions?
================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1650
+def err_type_defined_in_offsetof : Error<
+ "%0 cannot be defined in '__builtin_offsetof'">;
----------------
aaron.ballman wrote:
> We might want this change, we might not -- can you test the diagnostic behavior when using `#include <stddef.h>`? Does it print `__builtin_offsetof` in the following example?
> ```
> #include <stddef.h>
>
> int main() {
> return offsetof(struct S { int a; }, a);
> }
> ```
> when executed with `clang -fsyntax-only -ffreestanding -std=c2x test.c`
>
> If it prints the builtin name, I think we'll want to look at the builtin token to see if it was expanded from a macro named `offsetof` to improve the diagnostic quality.
```
local/offsetofcc.c:4:26: error: 'struct S' cannot be defined in '__builtin_offsetof'
return offsetof(struct S { int a; }, a);
^
1 error generated.
```
> If it prints the builtin name, I think we'll want to look at the builtin token to see if it was expanded from a macro named offsetof to improve the diagnostic quality.
OK
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133574/new/
https://reviews.llvm.org/D133574
More information about the cfe-commits
mailing list