-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Fold expressions miss parentheses #558
Comments
I quickly checked that at least for the operators |
Hello @Ukilele, thanks for reporting this issue! I agree with your quote from the standard. My issue is that at the point I render something like C++ Insights introduces parens in some cases, for example Line 720 in 50b962d
I wonder how your test looked for template<typename... Ts>
constexpr auto avg(const Ts&... vals)
{
return (vals + ...) / sizeof...(vals);
}
static_assert(avg(2, 3, 4) == 3); This translates to template<>
inline constexpr unsigned long avg<int, int, int>(const int & __vals0, const int & __vals1, const int & __vals2)
{
return (static_cast<unsigned long>(__vals0 + (__vals1 + __vals2))) / 3;
} As much as it bugs me, this issue will remain unfixed for now. Andreas |
Hello @andreasfertig, 1.) You're welcome. Thanks so much for this helpful tool! 🚀 2.) Yes, it seems that once you have a concrete 3.) Thanks for pointing at 4.) My test for Best regards, |
Hello @Ukilele, re 2.) Thanks for that idea. Sadly, even with The results for Everything is different for With the guessing, the effort, and the situation that it would still not work in all cases, I do not plan to do anything here. However. as always, PRs are welcome. Andreas |
Hello Andreas, there might be an issue with the transformation of fold expressions.
Following code:
generates following outcome:
In all four of my Test-functions, the issue is, that the fold expression does not contain the right amount of parentheses around them. According to https://eel.is/c++draft/temp.variadic#11, a unary left fold of the form
(... , Is)
should expand to( ((Is1, Is2) , ...) , IsN )
. But this is not, what cppinsights generates.I added four Test-functions.
TestA
andTestB
test the behavior with a function parameter pack, whileTestC
andTestD
test the behavior with a template parameter pack.TestA
andTestC
use the fold expression within a function call, whileTestC
andTestD
use the fold expression in an initialization. I did not check the behavior for the other kind of fold expressions (e.g. binary right fold) and other kind of operators, but I guess the behavior will be similar?Cheers!
The text was updated successfully, but these errors were encountered: