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

[BUG] Code Example Doesn't Compile #524

Closed
codereport opened this issue Apr 14, 2023 · 2 comments
Closed

[BUG] Code Example Doesn't Compile #524

codereport opened this issue Apr 14, 2023 · 2 comments

Comments

@codereport
Copy link

The following code example doesn't compile:

CppInsights Link: https://cppinsights.io/s/9b7c139b
image

The equivalent code on Godbolt does. I am not sure what is causing the issue but seems like it should work. Here is a twitter link with some discussion as well: https://twitter.com/code_report/status/1646638445555761152?s=20

@andreasfertig
Copy link
Owner

Hello @codereport,

thanks for raising this issue. The short answer is that C++ Insights still uses Clang 15, which does not support ranges (at least to my knowledge). I created an issue for the Clang update, #525.

The longer answer is it's more complicated.

In the link you provided, Clang is used with libstdc++ (from GCC) because that's the default under Linux. You can switch the lib under "More Transformation" (maybe not the best heading). Once C++ Insights uses Clang 16, that would work. I don't know why Clang doesn't seem to play well with libstdc++ regarding ranges.

Even with Clang 16, I believe you will not see what you are looking for because C++ Insights does only expand statements from the current source file. #428 provides an explanation. I can still imagine supporting this, but I assume that the resulting code could be a lot to process. I used an experimental version and... well... a lot of code was produced.

The following is the transformation result from my local C++ Insights version using Clang 16 (without the additional patch to dive into headers):

include <vector>
#include <ranges>

std::ranges::transform_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, __lambda_7_40> plus_one(std::vector<int, std::allocator<int> > && vec)
{

  class __lambda_7_40
  {
    public:
    template<class type_parameter_0_0>
    inline /*constexpr */ auto operator()(type_parameter_0_0 e) const
    {
      return e + 1;
    }

    #ifdef INSIGHTS_USE_TEMPLATE
    template<>
    inline /*constexpr */ int operator()<int>(int e) const
    {
      return e + 1;
    }
    #endif

    private:
    template<class type_parameter_0_0>
    static inline /*constexpr */ auto __invoke(type_parameter_0_0 e)
    {
      return __lambda_7_40{}.operator()<type_parameter_0_0>(e);
    }
    public:
    // inline /*constexpr */ __lambda_7_40() noexcept = default;
    // inline /*constexpr */ __lambda_7_40(__lambda_7_40 &&) noexcept = default;
    // /*constexpr */ __lambda_7_40() = default;

  } __lambda_7_40{};

  return operator|(vec, std::ranges::views::transform.operator()(__lambda_7_40));
}


int main()
{
  plus_one(std::vector<int, std::allocator<int> >{std::initializer_list<int>{1, 2, 3}});
  return 0;
}

Andreas

@andreasfertig
Copy link
Owner

Fixed by #569.

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