www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - dmd source code newsgroup?

reply Marco Leise <Marco.Leise gmx.de> writes:
Looking over the code handling the nothrow flag, I found a few
lines of code that I'd like to discuss with the language
designers. I don't see dmd source code discussions here, so I
wonder if there is another group outside of digitalmars.com ?

Anyway here is what I'd like to know and possibly fix...
The generated default constructor is created with no storage
class flags:

  class X {
      nothrow this() {
          writeln("I am a nothrow ctor");
      }
  }
  class Y : X {}

  nothrow void main() {  // constructor this is not nothrow
    new Y;
  }

  --- src/class.c:731 ---
  //printf("Creating default this(){} for class %s\n", toChars());
  Type *tf = new TypeFunction(NULL, NULL, 0, LINKd, 0);

I think it can be inferred as the parent's storage class.
The other point is attribute inference in src/func.c. Storage
classes like nothrow are only inferred if the function has a
body AND it is either a literal or part of a template.

  --- src/func.c:269 ---
  if (fbody &&
      (isFuncLiteralDeclaration() || parent->isTemplateInstance()))

Naively I would have guessed that having a function body is
sufficient to infer the attributes. On second though this
ensures that the whole type inference behavior doesn't
suddenly change if the function is put inside a library and
referenced through a .di file. Was that the idea behind it?

Ok, last question: parent->isTemplateInstance() is actually
keeping joiner() in std.algorithm from being inferred as
nothrow, because it only goes up one level. E.g. it works for
function templates, but not for templates containing structs
containing functions. Was that just an oversight or are there
technical reasons why there is no isNestedInATemplate()
function used there?

-- 
Marco
Aug 17 2012
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 08/17/2012 02:12 PM, Marco Leise wrote:
 Ok, last question: parent->isTemplateInstance() is actually
 keeping joiner() in std.algorithm from being inferred as
 nothrow, because it only goes up one level. E.g. it works for
 function templates, but not for templates containing structs
 containing functions. Was that just an oversight or are there
 technical reasons why there is no isNestedInATemplate()
 function used there?
Oversight. It shouldn't be done for virtual template member functions though. http://d.puremagic.com/issues/show_bug.cgi?id=7511
Aug 17 2012
parent Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 17 Aug 2012 15:09:31 +0200
schrieb Timon Gehr <timon.gehr gmx.ch>:

 Oversight. It shouldn't be done for virtual template member functions 
 though.
 
 http://d.puremagic.com/issues/show_bug.cgi?id=7511
I guess that's "welcome to the jungle" :) -- Marco
Aug 17 2012
prev sibling parent "Jacob Carlborg" <doob me.com> writes:
On Friday, 17 August 2012 at 12:13:37 UTC, Marco Leise wrote:
 Looking over the code handling the nothrow flag, I found a few
 lines of code that I'd like to discuss with the language
 designers. I don't see dmd source code discussions here, so I
 wonder if there is another group outside of digitalmars.com ?
There is a mailing list for these kind of discussions. This is the web front end for this: http://forum.dlang.org/group/dmd-internals -- /Jacob Carlborg
Aug 17 2012