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

--- Comment #0 from Don <> 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

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;

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to