Bug 22699 – importC: assignment cannot be used as a condition
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-23T06:32:03Z
Last change time
2022-01-29T09:27:55Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
dave287091
Comments
Comment #0 by dave287091 — 2022-01-23T06:32:03Z
C has the error-prone feature of assignment being an expression.
For example:
// assignexpr.c
int x;
int foo(int y){
if (x = y) // Error: assignment cannot be used as a condition, perhaps `==` was meant?
return 3;
return 0;
}
The CoreFoundation framework on macOS has a header with an inline function that uses this feature:
static inline __attribute__((always_inline))
void CFStringInitInlineBuffer(CFStringRef str, CFStringInlineBuffer *buf, CFRange range) {
buf->theString = str;
buf->rangeToBuffer = range;
buf->directCStringBuffer = (buf->directUniCharBuffer = CFStringGetCharactersPtr(str)) ? ((void*)0) : CFStringGetCStringPtr(str, kCFStringEncodingASCII);
buf->bufferedRangeStart = buf->bufferedRangeEnd = 0;
}
Comment #1 by dlang-bot — 2022-01-29T07:16:36Z
@WalterBright created dlang/dmd pull request #13580 "fix Issue 22699 - importC: assignment cannot be used as a condition" fixing this issue:
- fix Issue 22699 - importC: assignment cannot be used as a condition
https://github.com/dlang/dmd/pull/13580
Comment #2 by dlang-bot — 2022-01-29T09:27:55Z
dlang/dmd pull request #13580 "fix Issue 22699 - importC: assignment cannot be used as a condition" was merged into master:
- a53ebbb9a1c82a8448684cd43a43beb980eceaa4 by Walter Bright:
fix Issue 22699 - importC: assignment cannot be used as a condition
https://github.com/dlang/dmd/pull/13580