Bug 22598 – importC: Add support for __extension__ keyword

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-14T10:36:16Z
Last change time
2022-02-11T07:56:02Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
See also
https://issues.dlang.org/show_bug.cgi?id=21946

Comments

Comment #0 by ibuclaw — 2021-12-14T10:36:16Z
In common system headers, the __extension__ keyword can crop up, i.e in assert.h, assert() is defined as: --- # define assert(expr) \ ((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \ if (expr) \ ; /* empty */ \ else \ __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \ })) --- Here the __extension__ disables any ISO C warnings caused by the non-standards conforming syntax ({ ... }). By not allowing the same to be compilable by ImportC would prevent any code that uses assert.h from working.
Comment #1 by ibuclaw — 2021-12-15T09:57:55Z
I've worked around this by adding `#define __STRICT_ANSI__` to the sanitizer I run with the preprocessor.
Comment #2 by bugzilla — 2021-12-18T07:15:31Z
The __extension__ documentation is confusing: "You can prevent such warnings within one expression by writing `__extension__' before the expression. `__extension__' has no effect aside from this." Yet in your example, __extension__({ if (expr); else ...}) is a statement, not an expression.
Comment #3 by dave287091 — 2021-12-20T16:25:27Z
(In reply to Walter Bright from comment #2) > The __extension__ documentation is confusing: > > "You can prevent such warnings within one expression by > writing `__extension__' before the expression. `__extension__' has no > effect aside from this." > > Yet in your example, > > __extension__({ if (expr); else ...}) > > is a statement, not an expression. It’s a gnu statement expression. See https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html. It’s also supported by clang.
Comment #4 by bugzilla — 2022-01-22T01:26:56Z
(In reply to dave287091 from comment #3) > It’s a gnu statement expression. See > https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html. It’s also supported > by clang. Too bad there's no grammar for it.
Comment #5 by bugzilla — 2022-02-02T10:01:40Z
Once the `__extension__({ ... })` is parsed, what should the compiler do with it?
Comment #6 by dave287091 — 2022-02-03T04:18:00Z
(In reply to Walter Bright from comment #5) > Once the `__extension__({ ... })` is parsed, what should the compiler do > with it? There’s two things going on in that example: the __extension__ just suppresses some warning when it immediately precedes an expression. https://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html#index-_005f_005fextension_005f_005f In addition, there is a statement expression, which is a different gnu extension. That’s the statements wrapped by ({...}). So the compiler could just ignore __extension__ as it does nothing but suppress warnings. Supporting gnu statement expressions is a different issue and is more difficult.
Comment #7 by bugzilla — 2022-02-11T07:00:44Z
Documentation on __extension__ seems hard to come by. I found this: https://web.mit.edu/rhel-doc/3/rhel-gcc-en-3/alternate-keywords.html
Comment #8 by dlang-bot — 2022-02-11T07:02:27Z
@WalterBright created dlang/druntime pull request #3735 "fix Issue 22598 - importC: Add support for __extension__ keyword" fixing this issue: - fix Issue 22598 - importC: Add support for __extension__ keyword https://github.com/dlang/druntime/pull/3735
Comment #9 by bugzilla — 2022-02-11T07:03:43Z
The gcc `({ statement; })` is a whole 'nother thing.
Comment #10 by dlang-bot — 2022-02-11T07:56:02Z
dlang/druntime pull request #3735 "fix Issue 22598 - importC: Add support for __extension__ keyword" was merged into master: - 88538b642b582a8f01a27acb0575dd6679085c0a by Walter Bright: fix Issue 22598 - importC: Add support for __extension__ keyword https://github.com/dlang/druntime/pull/3735