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

Display the special operations generated by the compiler #224

Closed
viboes opened this issue Sep 27, 2019 · 6 comments
Closed

Display the special operations generated by the compiler #224

viboes opened this issue Sep 27, 2019 · 6 comments

Comments

@viboes
Copy link

viboes commented Sep 27, 2019

It would be great if the tool could show the special operations generated by the compiler as well as the ones requested using default.

struct C { 
  int i; 
};
struct C { 
  int i;
  C() = default; 
  C(C const&) = default; 
  C(C &&) = default; 
  C& operator=(C const&) = default; 
  C& operator=(C &&) = default; 
  ~C() noexcept = default;
};

In addition when the user request the default and the compiler deletes the function as he default generated will be ill formed, the tool could replace =default by =delete.

Before

struct C
{
  int & i;
  C() = default;
  C(const C &) = default;
};

https://cppinsights.io/s/cd13011a

After

struct C
{
  int & i;
  inline C() = delete;
  inline C(const C &) = delete;
};

P.S. I'm not asking to show the generated code, just to show what are the provided operations and which ones are deleted.

This doesn't mean thathaving the option to have the code as well will not be welcome.

@viboes
Copy link
Author

viboes commented Sep 27, 2019

Oh, I believe I start to understand what the tool is doing thanks to the reading of http://www.modernescpp.com/index.php/c-insights-conversions

The signatures are added only if used and really generated by the compiler.

While this could cover the good uses, it can not cover the bad uses as the code couln't compile.

Wondering of the interest of having the delete independetly of the usage.

@viboes
Copy link
Author

viboes commented Sep 27, 2019

And your blog https://www.andreasfertig.blog/2019/03/hello-c-insights.html
BTW, I didn't found those links on the About section.

@andreasfertig
Copy link
Owner

Hello @viboes,

that looks like an documentation issue. You have figured it out right, the special members are only show if they are used. The simple reason for that is, that Clang does not even border to generate them in the AST if they are not used.

Wondering of the interest of having the delete independetly of the usage.

This means making up the signature of the special members and by that introducing code that is not there in the first place. The question here is, is that a real benefit? Does it make the program easier and more intuitively to use?

BTW, why add hem as comments?

The idea here is to leave the input code as untouched as possible. Adding them for real changes the behavior, because now it is a user provided special member.

BTW, I didn't found those links on the About section.

Ah I see, you are talking about this sentence "The about page page already lists some examples."? I have to correct the article. I moved all the examples to a dedicated page examples.html

Andreas

@viboes
Copy link
Author

viboes commented Sep 28, 2019

Yes, it is a documenttaion issue that needs clarification.

As for =delete I believe this should be quite usefull for people learning C++ and even some more experimented people. We have already some warnings when we add =default and really what is behind the scenes is as if we had =delete. I can understand that this could be something difficult to do with clang as it is now or even impossible. I will add an issue even if it will be there to document the missing feature. I would nevertheless expect to have something in the documentaion in a limitations section.

For the comments, AFAIW, the use of =default will not change the behavior as far as it is done only at the declarations. In this case th eoperation is not considered user defined. We could consider it as an anhancement.

The missing links are for me on the documentaion of the tool. I woul dhad appreciate link to your blog and the Grimm's blog. We could consider it as an anhancement.

@viboes
Copy link
Author

viboes commented Sep 28, 2019

After the creation of these 4 issues, I believe we can close this one

#230 Add links to the blogs
#231 Add a section for each transformation with his limitations (special operations)
#232 Replace the use of comments for special operation by =default, =delete declarations
#233 Add a limitation respect to the enerated =deleted special operations

@viboes viboes closed this as completed Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants