-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
structure binding transformation is not accurate #226
Comments
The result of https://cppinsights.io/s/d9b470ff could be struct Point
{
int x;
int y;
// inline Point() = default;
// inline constexpr Point(const Point &) noexcept = default;
// inline constexpr Point(Point &&) = default;
};
void f(int, int);
Point pt = {1, 2};
void f()
{
Point __pt12 = Point(pt);
#define ax = __pt12.x;
#define ay = __pt12.y;
f(ax, ay);
#undef ax
#undef ay
} The use of define is stillnot accurate but IMO it conveys better the intent. //...
void f()
{
Point __pt12 = Point(pt);
f(__pt12.x, __pt12.y);
} Alternatively the transformation could add a comment on the variable declaration. // This is a workaround to have new names. You cannot take the address of these variables
int& ax = __pt12.x;
int& ay = __pt12.y; |
Hello @viboes, thank you for bringing up that issue. I agree that it is not 100% correct due to introducing new names. While I agree, that the I can look into the name replacement. I sadly had to do similar things for coroutines I'm working on, but it is not trivial and usually I like to leave as much AST parts untouched as I can. The comment is currently the easiest way to go I think. I was thinking about a annotation mode a user can turn on or off. C++ Insights for example already adds annotations for NRVO variables and other things (implicit special member functions you also have seen). Andreas |
I agree that the macro is not welcome. I understand that it is not easy to do the name replacement. If the comment is possible and easy, I believe all of us could live with. |
Hello @viboes, I just fixed another issue related to structured binding (#425). I read the wording a couple of times without seeing wording that says that the bindings are something special. I also looked at the code in Clang and couldn't find any special treatment. Unless somebody shows me a different interpretation of the standard or code in Clang that treats Andreas |
The structure binding transformation is not accurate, as the symbols are not real variables, thy are just names.
See the example
https://cppinsights.io/lnk?code=c3RydWN0IFBvaW50CnsKICBpbnQgeDsKICBpbnQgeTsKfTsKClBvaW50IHB0ezEsMn07Ci8vIEhlcmUgd2UgZ2V0IGFuIGFkZGl0aW9uYWwgb2JqZWN0IGluamVjdGVkIHRvIHdoaWNoIGF4IGFuZCBheSByZWZlci4KYXV0byBbYXgsIGF5XSA9IHB0OwoKLy8gSW4gY2FzZSBvZiBhbiByZWZlcmVuY2UgdGhlIGluamVjdGVkIG9iamVjdCBpcyBqdXN0IGEgcmVmZXJlbmNlIHRvCi8vIHRoZSBvcmlnaW5hbCBvbmUuCmF1dG8mIFthMngsIGEyeV0gPSBwdDs=&std=cpp17&rev=1.0
and this example with bitfields
https://cppinsights.io/s/a30c616b
The text was updated successfully, but these errors were encountered: