digitalmars.D.learn - Constructor template -- bug?
- Bekenn (27/27) Mar 01 2011 Code:
- Jonathan M Davis (8/43) Mar 01 2011 You cannot currently templatize class constructors:
- Jonathan M Davis (6/62) Mar 01 2011 I should also point out that there is absolutely no need to use template...
- Jacob Carlborg (5/67) Mar 01 2011 I guess the reason why he would do that is to catch the file and line
- Jonathan M Davis (6/75) Mar 02 2011 message,
- Jacob Carlborg (4/79) Mar 02 2011 Neither did I.
- Bekenn (3/7) Mar 02 2011 You are absolutely right; silly me. I'd assumed that would pick up the
Code: class MyException : Exception { this(string message, string file, size_t line, Throwable next = null) { super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(string message, Throwable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?
Mar 01 2011
On Tuesday 01 March 2011 22:18:49 Bekenn wrote:Code: class MyException : Exception { this(string message, string file, size_t line, Throwable next = null) { super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(string message, Throwable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749 - Jonathan M Davis
Mar 01 2011
On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote:On Tuesday 01 March 2011 22:18:49 Bekenn wrote:I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } - Jonathan M DavisCode: class MyException : Exception { this(string message, string file, size_t line, Throwable next = null) { super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(string message, Throwable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749
Mar 01 2011
On 2011-03-02 08:47, Jonathan M Davis wrote:On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote:I guess the reason why he would do that is to catch the file and line number where the constructor is called. -- /Jacob CarlborgOn Tuesday 01 March 2011 22:18:49 Bekenn wrote:I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } - Jonathan M DavisCode: class MyException : Exception { this(string message, string file, size_t line, Throwable next = null) { super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(string message, Throwable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749
Mar 01 2011
On Tuesday 01 March 2011 23:52:38 Jacob Carlborg wrote:On 2011-03-02 08:47, Jonathan M Davis wrote:null)On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote:On Tuesday 01 March 2011 22:18:49 Bekenn wrote:Code: class MyException : Exception { this(string message, string file, size_t line, Throwable next =message,{ super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(stringExcept that that works with normal default arguments. I assume that he did not realize that. - Jonathan M DavisI guess the reason why he would do that is to catch the file and line number where the constructor is called.I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } - Jonathan M DavisThrowable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749
Mar 02 2011
On 2011-03-02 09:07, Jonathan M Davis wrote:On Tuesday 01 March 2011 23:52:38 Jacob Carlborg wrote:Neither did I. -- /Jacob CarlborgOn 2011-03-02 08:47, Jonathan M Davis wrote:null)On Tuesday 01 March 2011 23:43:27 Jonathan M Davis wrote:On Tuesday 01 March 2011 22:18:49 Bekenn wrote:Code: class MyException : Exception { this(string message, string file, size_t line, Throwable next =message,{ super(message, file, line, next); } this(string file = __FILE__, size_t line = __LINE__)(stringExcept that that works with normal default arguments. I assume that he did not realize that. - Jonathan M DavisI guess the reason why he would do that is to catch the file and line number where the constructor is called.I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... } - Jonathan M DavisThrowable next = null) { this(message, file, line, next); } } void main() { throw new MyException("Bluh!"); } Error message: test.d(8): Error: template test.MyException.__ctor(string file = __FILE__,size_t line = __LINE__) conflicts with constructor test.MyException.this at test.d(3) If I remove the normal constructor and call super instead of this from the constructor template, then I get this slightly different error message: test.d(1): Error: constructor test.MyException.this conflicts with template test.MyException.__ctor(string file = __FILE__,uint line = __LINE__) at test.d(3) Is this a compiler bug, or am I Doing It Wrong?You cannot currently templatize class constructors: http://d.puremagic.com/issues/show_bug.cgi?id=435 And currently if one overload of a function is templatized, _all_ overloads of that function must templatized: http://d.puremagic.com/issues/show_bug.cgi?id=2972 http://d.puremagic.com/issues/show_bug.cgi?id=4749
Mar 02 2011
On 3/1/2011 11:47 PM, Jonathan M Davis wrote:I should also point out that there is absolutely no need to use template for what you're trying to do. Just declare the constructor like so: this(string message, string file = __FILE__, size_t line = __LINE__ Throwable next = null) { ... }You are absolutely right; silly me. I'd assumed that would pick up the file and line at the point of declaration...
Mar 02 2011