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

Make lifetime extension explicit #156

Closed
BenFrantzDale opened this issue Mar 26, 2019 · 3 comments
Closed

Make lifetime extension explicit #156

BenFrantzDale opened this issue Mar 26, 2019 · 3 comments
Labels
enhancement New feature or request stale No activity

Comments

@BenFrantzDale
Copy link

Thanks for creating such a cool tool!

It would be great if lifetime extension were made explicit. That is, the GOTW#88 const& behavior: https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/

as in

struct C { virtual int get() const { return 0; } };
struct D : C { virtual int get() const override { return 1; } };

int foo() {
	const C& c = D();
  	return c.get();
}

Right now the above produces

...
int foo()
{
  const C & c = static_cast<const C&>(D());
  return c.get();
}

which is correct, but the insight I'd like to see would show that after the return, c is destroyed with D::~D().

I'm not sure how you'd show that in the output, though... Maybe in a comment?

@andreasfertig
Copy link
Owner

Hello @BenFrantzDale,

thank you, my pleasure.
I totally agree, it would be great. However, have a look at this discussion on the Clang developers list. Object lifetime is not modeled in the AST.
I haven't looked into how the static analyzer does it as the comment also suggests. I will do that as soon as I find the time for it. So far assume that it is impossible and will not be part of C++ Insights. But of course, feel free to show me a way.

Andreas

@stale
Copy link

stale bot commented May 25, 2019

Thanks for contributing to this issue. As it has been 60 days since the last activity waiting for a followup. This issue will be automatically closed in 7 days, if no further activity occurs. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please respond before the issue is closed. We'll gladly take a look again! In any case, thank you for your contributions!

@stale stale bot added the stale No activity label May 25, 2019
@andreasfertig andreasfertig added enhancement New feature or request and removed stale No activity labels May 31, 2019
@stale stale bot added the stale No activity label Jul 30, 2019
@andreasfertig andreasfertig removed the stale No activity label Aug 2, 2019
Repository owner deleted a comment from stale bot Aug 2, 2019
@stale
Copy link

stale bot commented Oct 1, 2019

Thanks for contributing to this issue. As it has been 60 days since the last activity waiting for a followup. This issue will be automatically closed in 7 days, if no further activity occurs. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please respond before the issue is closed. We'll gladly take a look again! In any case, thank you for your contributions!

@stale stale bot added the stale No activity label Oct 1, 2019
@stale stale bot closed this as completed Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale No activity
Projects
None yet
Development

No branches or pull requests

2 participants