Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7525107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:26:51+00:00 2026-05-30T03:26:51+00:00

import std.stdio; struct S { string m_str = "defaultString"; this(this) { writeln("In this(this)"); }

  • 0
import std.stdio;

struct S
{
    string m_str = "defaultString";
    
    this(this)
    {
        writeln("In this(this)");
    }
    
    ~this()
    {
        writeln("In ~this():"~m_str);
    }
    
}

struct Holder
{
    S[] m_arr;
    S m_s;
    
    this(S[] arr)
    {
        m_arr = arr;
        m_s.m_str="H.m_s";
    }
    
    S getSMem()
    {
        return m_s;
    }
    
    S getSVec()
    {
        return m_arr[0];
    }
    
    S getSLocal()
    {
        S local = S("localString");
        return local;
    }
}

void main()
{
    Holder h = Holder(new S[1]);
    
    S s1 =  h.getSMem();
    S s2 =  h.getSVec();
    S s3 =  h.getSLocal();
}

The above in D2.058 gives:

In this(this)

In ~this():localString

In ~this():defaultString

In ~this():H.m_s

In ~this():H.m_s

Only one this(this) is produced in the above (from the getSMem() call). The getSLocal() call can just move the struct. However, why does getSVec() not result in a this(this)? I noticed this is the context of a reference counting struct held in a std.container.Array, and there were too few calls to this(this) compared to ~this().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:26:52+00:00Added an answer on May 30, 2026 at 3:26 am

    In the case of getSVec, it looks like a bug, possibly related to this one, though the situation is not exactly the same. You should report your specific example though, since it may not be the exact same bug.

    However, as you say, in the case of getSLocal, the local variable is moved, so no copying takes place, and no postblit call is required. It’s just getSVec which is buggy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello World for D looks like this: import std.stdio; void main(string[] args) { writeln(Hello
import std.stdio; struct Vector2 { float x, y; this (float x, float y) {
import std.stdio; void main(){ int n; while(readf("%d", &n)){ if(n == 11) break; writeln(n); }
Testing the following in D import std.stdio; struct S { int _val; @property ref
std.process has a nice shell() function. import std.process; import std.stdio; void main() { string
Linking the following two files gives me a link-error: a.d: import std.stdio; extern string
I have the following code in D import std.stdio; class Thing { // Fields
i did this code : from scitools.std import * npoints=10 vectorpoint=array(random.uniform(-1,1,[1,2])) experiment=array(random.uniform(-1,1,[npoints,2])) print(vectorpoint=,vectorpoint) print(experiment=,experiment)
I did this code: from scitools.std import * from sympy import * x=Symbol('x') #Integral
Consider the following code: module ftwr; import std.regex; import std.stdio; import std.conv; import std.traits;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.