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

Incorrect code generation for IIFE inside if without parentheses #386

Closed
TerensTare opened this issue Mar 12, 2021 · 3 comments · Fixed by #388
Closed

Incorrect code generation for IIFE inside if without parentheses #386

TerensTare opened this issue Mar 12, 2021 · 3 comments · Fixed by #388
Labels
bug Something isn't working

Comments

@TerensTare
Copy link

TerensTare commented Mar 12, 2021

First of all, I want to thank you for making CppInsights, it is a great and handy tool.
Then, consider the following C++20 code:

#include <utility>

namespace tnt
{
    // vector
    template <typename T, std::size_t N>
    struct vector final
    {
      static_assert(N > 0);
      
        template <typename U, std::size_t S>
        constexpr vector& operator=(vector<U, S> &&rhs) noexcept
        {
            if (this != &rhs)
                [this, rhs = std::move(rhs)]
                    <std::size_t... I>(std::index_sequence<I...>) noexcept {
                    ((data[I] = std::exchange(rhs.data[I], U(0))), ...);
                }(std::make_index_sequence<S>{});
            return *this;
        }

    private:
        T data[N]{};
    };
} // namespace tnt

int main()
{
}

As it can be seen from the generated code of the move assignment operator, the lambda is generated inside the if clause, and then called outside the if. The part from the generated lambda-class body and after the invocation of the lambda should be inside the if (surrounded by { and }).

@andreasfertig andreasfertig added the bug Something isn't working label Mar 17, 2021
@andreasfertig
Copy link
Owner

andreasfertig commented Mar 17, 2021

Hello @TerensTare,

my pleasure! Thanks for reporting this. It took a bit longer than usual because this issue is not just present with if. It is wrong for while, do ... while, and for as well. As a bonus, the example above revealed that finalwas inserted at the wrong position. So you reported two bugs at once :-) A fix is on its way.

Andreas

@TerensTare
Copy link
Author

My pleasure to be of help! As for for the final, I have noticed it but I thought this was the intended behaviour😅.
Thank you once again,

Terens

@andreasfertig andreasfertig linked a pull request Mar 17, 2021 that will close this issue
@andreasfertig
Copy link
Owner

Every bug counts! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants