D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3450 - incorrect result for is (typeof({ ... }())) inside a struct
Summary: incorrect result for is (typeof({ ... }())) inside a struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 critical
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2009-10-29 08:19 UTC by kamaboco
Modified: 2015-06-09 01:26 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kamaboco 2009-10-29 08:19:37 UTC
struct Foo
{
    enum bool BAR = is (typeof({}()));
    // Error: static assert  (0 == 1) is false
    static assert (BAR == is (typeof({}())));
}
Comment 1 Don 2010-01-16 23:30:16 UTC
PATCH: in FuncDeclaration::semantic3(), it's forbidden to use function literals as class members. But, it should be OK to use them inside a typeof() expression.
----------

Index: func.c
===================================================================
--- func.c	(revision 335)
+++ func.c	(working copy)
@@ -789,14 +789,14 @@
 	if (ad)
 	{   VarDeclaration *v;
 
-	    if (isFuncLiteralDeclaration() && isNested())
+	    if (isFuncLiteralDeclaration() && isNested() && !sc->intypeof)
 	    {
 		error("literals cannot be class members");
 		return;
 	    }
 	    else
 	    {
-		assert(!isNested());	// can't be both member and nested
+		assert(!isNested() || sc->intypeof);	// can't be both member and nested
 		assert(ad->handle);
 		Type *thandle = ad->handle;
 #if STRUCTTHISREF
Comment 2 Walter Bright 2010-02-05 19:54:33 UTC
changeset 371
Comment 3 Kosmonaut 2010-02-05 23:39:34 UTC
(In reply to comment #2)
> changeset 371

http://www.dsource.org/projects/dmd/changeset/371
Comment 4 Walter Bright 2010-03-08 22:20:53 UTC
Fixed dmd 1.057 and 2.041