[Issue 5092] New: pure nothrow should be ignored for unit tests
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Oct 21 06:51:07 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5092
Summary: pure nothrow should be ignored for unit tests
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Keywords: patch
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: clugdbug at yahoo.com.au
--- Comment #0 from Don <clugdbug at yahoo.com.au> 2010-10-21 06:50:18 PDT ---
import std.stdio;
pure nothrow:
int foo(int z) { return z*2; }
unittest {
writeln("testing foo");
assert(foo(4) == 8);
}
---
This won't compile, because the unit test calls writeln which is impure and may
throw.
It makes no sense for a unittest to be nothrow. And it's really a nuisance.
And if a unittest isn't conceptually pure, you have a big problem anyway -- the
program behaviour will change depending on whether unittests are run, or not.
PATCH: func.c, around line 3460
void UnitTestDeclaration::semantic(Scope *sc)
{
if (global.params.useUnitTests)
{
if (!type)
type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
Scope *sc2 = sc->push();
+ // It makes no sense for unit tests to be pure or nothrow.
+ sc2->stc &= ~(STCnothrow | STCpure);
sc2->linkage = LINKd;
FuncDeclaration::semantic(sc2);
sc2->pop();
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list