Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the way how default construction is visualized #406

Open
venkat-gvk opened this issue Jul 1, 2021 · 2 comments
Open

Changing the way how default construction is visualized #406

venkat-gvk opened this issue Jul 1, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@venkat-gvk
Copy link

Here is the code:

struct Box {
  Box(const char*) {}
};

template <typename T>
struct Vector {
  explicit Vector(T) {}
};

int main() {
  Vector<Box> s { "one" };
}

The output it produces:

struct Box
{
  inline Box(const char *)
  {
  }
  
};

template <typename T>
struct Vector {
  explicit Vector(T) {}
};

/* First instantiated from: insights.cpp:11 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
struct Vector<Box>
{
  inline explicit Vector(Box)
  {
  }
  
};

#endif

int main()
{
  Vector<Box> s = Vector<Box>{Box("one")}; 
}

The expression Vector<Box> s = Vector<Box>{Box("one")}; looks like a temporary of Vector of Box is created and it is move initialized. Yes starting from C++17 onwards it is elided. But it looks like copy/move.

If we change the output to something like Vector<Box> s { Box("one") } instead, it will match the default construction. If the class has an initializer_list constructor, the syntax would choose that. It will help distinguish copy/move and default initialization.

Thanks.

@andreasfertig
Copy link
Owner

Hello @venkat-gvk,

thanks for reporting this. There is already an issue open (#120) that addresses the same issue. Your suggestion seems to be an approach. The downside is that it requires filtering the initializer. What we all currently see is what is in the AST. To make work what you describe I need to filter out the call to the constructor. I have a prototype that does this, but I'm reluctant about how stable it is and what specialties I missed.

Andreas

@andreasfertig andreasfertig added the enhancement New feature or request label Jul 19, 2021
@venkat-gvk
Copy link
Author

Thanks for the Reply. Looking forward to the prototype

andreasfertig added a commit that referenced this issue Feb 5, 2022
While this fix addresses the original issue, the construction of an
array as shown is invalid. This could be something resolved by #406.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants