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

Object creation is erroneously explained with a copy construction #120

Open
GPopov opened this issue Feb 11, 2019 · 3 comments
Open

Object creation is erroneously explained with a copy construction #120

GPopov opened this issue Feb 11, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@GPopov
Copy link

GPopov commented Feb 11, 2019

Creating an object of some class is explained as if a copy construction is performed, which is not the case for standard-compliant compilers.

Example:

struct A
{
    A() = default;
    A(const A&) = delete;
};

int main()
{
    A a; //1
}

The line (1) is transformed into:
A a = A();

This is wrong, as it would invoke the deleted copy ctor of A. Proof: https://godbolt.org/z/wct9r5

@andreasfertig
Copy link
Owner

Hello @GPopov,

thank you for reporting that finding. How would you like the default ctor to be visualized?

Andreas

@GPopov
Copy link
Author

GPopov commented Feb 15, 2019

This is an interesting and difficult question. If there was a obviously really more expressive way, most probably the C++ committee would have opted for it already. A very suboptimal soultion would be as a comment, detailing all the relevant c-tors and special member functions that get invoked.
Something along the lines of

A a;
A a2 = a;
A a3 = A();

transformed into

//A::A()
A a;

//A::A(const A&)
A a2 = a;
// 1. A::A() 2. A::(const A&) 
A a3 = A();

This solution has multiple problems with it, starting with the fact that if the line is rather more complicated, this comment would quickly just as difficult to understand as the original line. Maybe some plain-english explanation could be thought about, again as a comment, but this feels a bit against the goal of your project.

As a starting point, I'd say that at the very least and a starting point, no incorrect explanation should be produced.

@andreasfertig
Copy link
Owner

Yes it is indeed difficult. I agree that nothing incorrect should be produced. On the other hand, without a proper alternative I feel reluctant to just remove it. I like to think more about it.

@stale stale bot added the stale No activity label Apr 22, 2019
@andreasfertig andreasfertig added the enhancement New feature or request label Apr 28, 2019
@stale stale bot removed the stale No activity label Apr 28, 2019
@stale stale bot added the stale No activity label Jun 27, 2019
@andreasfertig andreasfertig removed the stale No activity label Jun 28, 2019
@stale stale bot added the stale No activity label Aug 27, 2019
@stale stale bot closed this as completed Sep 3, 2019
@andreasfertig andreasfertig reopened this Sep 7, 2019
@stale stale bot removed the stale No activity label Sep 7, 2019
Repository owner deleted a comment from stale bot Sep 7, 2019
Repository owner deleted a comment from stale bot Sep 7, 2019
Repository owner deleted a comment from stale bot Sep 7, 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
Projects
None yet
Development

No branches or pull requests

2 participants