Bug 4303 – __traits(compiles) returns wrong result when used recursively
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-06-13T03:16:00Z
Last change time
2010-06-28T11:35:53Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
r.sagitario
Comments
Comment #0 by r.sagitario — 2010-06-13T03:16:47Z
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.