The following fails with 'Error: this for x needs to be type C not type int': class C { int x; } typeof(C.x) z;
Not sure if that's really a bug or not. I lean towards "no" since typeof is supposed to take a variable, and C.x is not a variable. You can get what you want with typeof(C.init.x).
I'm not sure either as it worked before but is not mentioned in the specs. I wouldn't post it as bug if the following compiled: static assert (!is(typeof(C.x))); // Fails with the same error, should pass static assert (!__traits(compiles, C.x)); // Should pass ... and if this didn't compile: struct S { int x; } typeof(S.x) y; // Why this compiles then? So it is either a regression or we have other bugs and inconsistencies.
in the essence, it's duplicated with bug 515 *** This bug has been marked as a duplicate of 515 ***
No, 515 is about whether .offsetof is static or not. This is about whether typeof(Class.nonstatic) should be allowed.
(In reply to comment #1) > Not sure if that's really a bug or not. I lean towards "no" since typeof is > supposed to take a variable, and C.x is not a variable. It's supposed to take an expression. C.x is an expression. > > You can get what you want with typeof(C.init.x). >
> It's supposed to take an expression. C.x is an expression. C.x is not a valid expression?
This example shows it's definitely a bug (1.047): class C { int x; } alias C.x F; static assert(is(typeof(F) == int)); // OK static assert(is(typeof(C.x) == int)); //Error: static assert (is(int == int)) is false
PATCH: mtype.c, in TypeClass::dotExp(), around line 6350 in D2.032. Don't convert class.x into this.x if inside a typeof() and we don't have a 'this'. -------- /* It's: * Class.d */ if (d->isTupleDeclaration()) { e = new TupleExp(e->loc, d->isTupleDeclaration()); e = e->semantic(sc); return e; } - else if (d->needThis() && (hasThis(sc) || !d->isFuncDeclaration())) + else if (d->needThis() && (hasThis(sc) || (!sc->intypeof && !d->isFuncDeclaration()))) { if (sc->func) { ClassDeclaration *thiscd; thiscd = sc->func->toParent()->isClassDeclaration(); -------
Fixed dmd 1.048 and 2.033
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル