4303 – __traits(compiles) returns wrong result when used recursively

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4303 - __traits(compiles) returns wrong result when used recursively
Summary: __traits(compiles) returns wrong result when used recursively
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: patch, wrong-code
Depends on:
Blocks:
Reported: 2010年06月13日 03:16 UTC by Rainer Schuetze
Modified: 2010年06月28日 11:35 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2010年06月13日 03:16:47 UTC
compiling this code:
///
template foo()
if (__traits(compiles,undefined))
{
	enum foo = false;
}
template foo()
if (true)
{
	enum foo = true;
}
pragma(msg,__traits(compiles,foo!()));
const bool bar = foo!();
/////
compiles, but outputs:
false
This is caused by __traits(compiles) not restoring the global error count in recursive calls (more specifically: when the error output is gagged before evaluating __traits).
Here's the patch:
Index: traits.c
===================================================================
--- traits.c	(revision 532)
+++ traits.c	(working copy)
@@ -397,8 +397,8 @@
 
 global.gag--;
 if (errors != global.errors)
- { if (global.gag == 0)
- global.errors = errors;
+ {
+ global.errors = errors;
 goto Lfalse;
 }
 }
Issue 3448 seems similar, but this patch does not help there.
Comment 1 Walter Bright 2010年06月28日 11:35:53 UTC
http://www.dsource.org/projects/dmd/changeset/565 


AltStyle によって変換されたページ (->オリジナル) /