Skip to content

Incorrect code generation for IIFE inside if without parentheses #386

@TerensTare

Description

@TerensTare

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 }).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions