[dmd-internals] runnable/sdtor.d

Brad Roberts braddr at puremagic.com
Thu Jun 2 09:04:11 PDT 2011


With the changes to switch to require a default handler, there's some fall-out in runnable/sdtor.d.

line 1271:
  if (0) switch(1) A51 a;

runnable/sdtor.d(1271): Error: non-final switch statement must have a default

So, is d (and thus dmd) supposed to deal with that case better?  I assume no since there's no case 1:, and that the test
should be changed to:
  if (0) switch(1) { A51 a; default: }

Of course, the opposite is also interesting in terms of 'in what cases is a actually constructed/destructed':
  if (0) switch(1) { default: A51 a; }

Lastly, now that struct dtors are working, all of those cases should probably be updated to validate that the dtor is
actually called.

With that in mind, review this diff.  Particularly the last line of the test, I think the current behavior is wrong.

$ git diff
diff --git a/test/runnable/sdtor.d b/test/runnable/sdtor.d
index 1f95710..45c3867 100644
--- a/test/runnable/sdtor.d
+++ b/test/runnable/sdtor.d
@@ -1249,28 +1249,31 @@ void test50()

 /**********************************/

+int A51_a;
+
 struct A51
 {
-    ~this() { }
+    ~this() { ++A51_a; }
 }

 void test51()
 {
-  while(0) A51 a;
-  if(0) A51 a;
-  if(1){} else A51 a;
-  for(;0;) A51 a;
-  if (1) { A51 a; }
-  if (1) A51 a;
-  if(0) {} else A51 a;
-  if (0) for(A51 a;;) {}
-  if (0) for(;;) A51 a;
-  do A51 a; while(0);
-  if (0) while(1) A51 a;
-  try A51 a; catch(Error e) {}
-  if (0) switch(1) A51 a;
-  final switch(0) A51 a;
-  A51 a; with(a) A51 b;
+  A51_a = 0; while(0) A51 a;                      assert(A51_a == 0);
+  A51_a = 0; if(0) A51 a;                         assert(A51_a == 0);
+  A51_a = 0; if(1){} else A51 a;                  assert(A51_a == 0);
+  A51_a = 0; for(;0;) A51 a;                      assert(A51_a == 0);
+  A51_a = 0; if (1) { A51 a; }                    assert(A51_a == 1);
+  A51_a = 0; if (1) A51 a;                        assert(A51_a == 1);
+  A51_a = 0; if(0) {} else A51 a;                 assert(A51_a == 1);
+  A51_a = 0; if (0) for(A51 a;;) {}               assert(A51_a == 0);
+  A51_a = 0; if (0) for(;;) A51 a;                assert(A51_a == 0);
+  A51_a = 0; do A51 a; while(0);                  assert(A51_a == 1);
+  A51_a = 0; if (0) while(1) A51 a;               assert(A51_a == 0);
+  A51_a = 0; try A51 a; catch(Error e) {}         assert(A51_a == 1);
+  A51_a = 0; if (0) switch(1) { A51 a; default: } assert(A51_a == 0);
+  A51_a = 0; if (0) switch(1) { default: A51 a; } assert(A51_a == 0);
+  A51_a = 0; final switch(0) A51 a;               assert(A51_a == 0);
+  A51_a = 0; A51 a; with(a) A51 b;                assert(A51_a == 1); // should be 2, right?
 }

Later,
Brad


More information about the dmd-internals mailing list