www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - __gshared this()

reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
I has problems:

class T
{
__gshared int global;
int member;

this()
{
member = global;
}

__gshared this()
{
global = 10;
}
}

fatal error LNK1179: invalid or corrupt file: duplicate COMDAT
'_D2db2ui2ui1T6__ctorMFZC2db2ui2ui1T (db.ui.ui.T db.ui.ui.T.__ctor())'



Further, if I write this code:

  void f()
  {
T t = new T;
  }

Error: db.ui.ui.T.__ctor called with argument types () matches both:
     db.ui.ui.T.this()
and:
     db.ui.ui.T.this()

It seems __gshared constructors aren't working... although I thought they
did; I'm sure I've used them before in various occasions :/
Jul 21 2014
parent reply Jacob Carlborg <doob me.com> writes:
On 22/07/14 08:25, Manu via Digitalmars-d wrote:

 It seems __gshared constructors aren't working... although I thought
 they did; I'm sure I've used them before in various occasions :/
What would that do? I didn't know that was possible to do. -- /Jacob Carlborg
Jul 21 2014
parent reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
We have:
  this()   // instance constructor
  static this()  // thread-local static constructor

But what I need is:
  __gshared this()   // not-thread-local static constructor (?)


On 22 July 2014 16:31, Jacob Carlborg via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

 On 22/07/14 08:25, Manu via Digitalmars-d wrote:

  It seems __gshared constructors aren't working... although I thought
 they did; I'm sure I've used them before in various occasions :/
What would that do? I didn't know that was possible to do. -- /Jacob Carlborg
Jul 22 2014
next sibling parent reply "David Nadlinger" <code klickverbot.at> writes:
On Tuesday, 22 July 2014 at 07:27:46 UTC, Manu via Digitalmars-d 
wrote:
 But what I need is:
   __gshared this()   // not-thread-local static constructor
"shared static this()" (or the other b way round, can never remember). Cheers, David
Jul 22 2014
next sibling parent Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 22 July 2014 17:47, David Nadlinger via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

 On Tuesday, 22 July 2014 at 07:27:46 UTC, Manu via Digitalmars-d wrote:

 But what I need is:
   __gshared this()   // not-thread-local static constructor
"shared static this()" (or the other b way round, can never remember). Cheers, David
Oh wow, I'm an idiot. Not sure how I missed that... and I've even used it before in various occasions! Sorry for the noise! >_<
Jul 22 2014
prev sibling parent reply Manu via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 22 July 2014 18:26, Manu <turkeyman gmail.com> wrote:

 On 22 July 2014 17:47, David Nadlinger via Digitalmars-d <
 digitalmars-d puremagic.com> wrote:

 On Tuesday, 22 July 2014 at 07:27:46 UTC, Manu via Digitalmars-d wrote:

 But what I need is:
   __gshared this()   // not-thread-local static constructor
"shared static this()" (or the other b way round, can never remember). Cheers, David
Oh wow, I'm an idiot. Not sure how I missed that... and I've even used it before in various occasions! Sorry for the noise! >_<
Might I suggest some helpful error messages in these cases where the user tries to do something stupid like this? :)
Jul 22 2014
parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Tuesday, 22 July 2014 at 08:33:57 UTC, Manu via Digitalmars-d 
wrote:
 Might I suggest some helpful error messages in these cases 
 where the user
 tries to do something stupid like this? :)
You may :-) https://issues.dlang.org/
Jul 22 2014
prev sibling parent "Peter Alexander" <peter.alexander.au gmail.com> writes:
On Tuesday, 22 July 2014 at 07:27:46 UTC, Manu via Digitalmars-d 
wrote:
 We have:
   this()   // instance constructor
   static this()  // thread-local static constructor

 But what I need is:
   __gshared this()   // not-thread-local static constructor (?)
shared static this() { ... } http://dlang.org/class#SharedStaticConstructor
Jul 22 2014