Bug found ??

Thorsten Kiefer thorstenkiefer at gmx.de
Sat Mar 3 19:14:41 PST 2007


Hi,
the following code works fine :

import std.stdio;
import test4mod;


char[] d_problem(T)(T x){
	static if(is(T B == B[])) {
		return "[" ~ d_problem(x[0]) ~ "]";
	} else {
		return "bla";
	}
}

void main(char[][] args){
	int[][] x = [[1,2,3]];
	writefln("%s",d_problem(x));
}

The outout is : [[bla]]


If I split this into 2 files :

import std.stdio;
import test4mod;
void main(char[][] args){
	int[][] x = [[1,2,3]];
	writefln("%s",d_problem(x));
}

module test4mod;
char[] d_problem(T)(T x){
	static if(is(T B == B[])) {
		return "[" ~ d_problem(x[0]) ~ "]";
	} else {
		return "bla";
	}
}

If you run this progam, you get a "segmentation fault". A bug ?

It can be corrected :

import std.stdio;
import test4mod;
void main(char[][] args){
	int[][] x = [[1,2,3]];
	writefln("%s",d_problem(x));
}

module test4mod;
char[] d_problem(T)(T x){
     static char[] a = "[",b = "]";
	static if(is(T B == B[])) {
		return a ~ d_problem(x[0]) ~ b;
	} else {
		return "bla";
	}
}

This works fine again.



More information about the Digitalmars-d mailing list