Bug 12041 – Strange warning pragma when instantiating WhiteHole
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-30T02:01:00Z
Last change time
2014-01-30T03:40:03Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2014-01-30T02:01:44Z
Phobos has been emitting this diagnostic lately, the reduced case is:
-----
import std.typecons;
interface I
{
void bar() nothrow;
}
void main()
{
new WhiteHole!I;
}
-----
$ dmd test.d
> Warning: WhiteHole!(I) used assert(0) instead of Error for the auto-implemented nothrow function I.bar
There is no file+line info, and I don't understand the diagnostic at all?
Comment #1 by andrej.mitrovich — 2014-01-30T02:03:09Z
Oh nevermind, it's actually an internal pragma emitted from:
/// ditto
template generateAssertTrap(C, func.../+[BUG 4217]+/)
{
static if (functionAttributes!(func) & FunctionAttribute.nothrow_) //XXX
{
pragma(msg, "Warning: WhiteHole!(", C, ") used assert(0) instead ",
"of Error for the auto-implemented nothrow function ",
C, ".", __traits(identifier, func));
enum string generateAssertTrap =
`assert(0, "` ~ C.stringof ~ "." ~ __traits(identifier, func)
~ ` is not implemented");`;
}
else
enum string generateAssertTrap =
`throw new NotImplementedError("` ~ C.stringof ~ "."
~ __traits(identifier, func) ~ `");`;
}
However I still don't understand the diagnostic. I'll change this to be a library issue.
Comment #2 by k.hara.pg — 2014-01-30T02:44:21Z
(In reply to comment #1)
> However I still don't understand the diagnostic. I'll change this to be a
> library issue.
In old days, throwing Error from nothrow function had caused "function foo is nothrow yet may throw" error. As a workaround, WhiteHole used assert(0) instead throwing NotImplementedError for abstract nothrow functions.
It's also noted in BUGS section of WhiteHole.
BUGS:
Nothrow functions cause program to abort in release mode because the trap is
implemented with $(D assert(0)) for nothrow functions.
But today, the compiler/lamguage limitation is already removed. So we can just remove the workaround code from WhileHole implementation.
Phobos fix:
https://github.com/D-Programming-Language/phobos/pull/1892
Comment #3 by github-bugzilla — 2014-01-30T03:22:34Z