D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7194 - [CTFE] Incorrect behaviour with pointers as local struct variable fields
Summary: [CTFE] Incorrect behaviour with pointers as local struct variable fields
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-01 03:15 UTC by Denis Shelomovskii
Modified: 2015-06-09 05:11 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2012-01-01 03:15:04 UTC
---
struct S { int* p, p2; }

int f() {
    assert(S().p == null);   // passes
    assert(!S().p);          // passes
    assert(S().p == S().p2); // passes

    auto s = S();
    assert(!s.p); // passes, note: `s.p` also passes
    assert(s.p == null); // fails
    assert(s.p == s.p2); // fails
    return 0;
}

int g() {
    auto s = S();
    assert(s.p);  // passes but should fail
    return 0;
}

void t()() { enum e = g(); } // const for D1

static assert(f() == 0);
// static assert is in a function because of @@@BUG3448@@@ aka @@@BUG965@@@
void f3448() { static assert(!__traits(compiles, t!()())); } // is(typeof()) for D1
---