4067 – [CTFE] Code inside try-catch blocks is silently ignored

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4067 - [CTFE] Code inside try-catch blocks is silently ignored
Summary: [CTFE] Code inside try-catch blocks is silently ignored
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2010年04月05日 05:52 UTC by bearophile_hugs
Modified: 2015年06月09日 05:13 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010年04月05日 05:52:22 UTC
Usually I show here minimal programs that contain the bug, but this time I show a bigger small program.
This is a small benchmark I've adapted from the old Shootout code, it tests the performance of exceptions (on dmd they are very slow).
I use this code both at compile time and run time.
It contains a printf and exceptions that can't be used in CTFE, but this program compiles with dmd v.2.042 and prints 0/0 at ctfe.
import std.c.stdio: printf;
class LoException : Exception {
 this() {
 super(null);
 }
}
class HiException : Exception {
 this() {
 super(null);
 }
}
struct HiLo { int hi, lo; }
struct App {
 int hi, lo, count;
 void someFunction() {
 try {
 hiFunction();
 } catch (Exception e) {
 printf("We shouldn't get here\n");
 }
 }
 void hiFunction() {
 try {
 loFunction();
 } catch (HiException) {
 hi++;
 }
 }
 void loFunction() {
 try {
 blowUp();
 } catch (LoException) {
 lo++;
 }
 }
 void blowUp() {
 if (count & 1)
 throw new HiException();
 else
 throw new LoException();
 }
 auto go(int n) {
 for (count = 0; count < n; count++)
 someFunction();
 return HiLo(hi, lo);
 }
}
void main() {
 enum int n = 1000;
 App app;
 HiLo result1 = app.go(n); // OK
 printf("excepts(%d) hi|lo = %d | %d\n", n, result1.hi, result1.lo);
 enum HiLo result2 = app.go(n); // Err
 printf("excepts(%d) hi|lo = %d | %d\n", n, result2.hi, result2.lo);
}
Comment 1 Don 2010年04月06日 06:30:42 UTC
This should generate an error, until exceptions are supported in CTFE.
Comment 2 Walter Bright 2010年04月28日 08:31:02 UTC
changeset 457
Comment 3 Don 2010年05月05日 19:09:17 UTC
Fixed DMD2.044


AltStyle によって変換されたページ (->オリジナル) /