https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100205

            Bug ID: 100205
           Summary: [11 Regression] error: invalid use of non-static data
                    member
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
  Target Milestone: ---

Hi gcc-team,

the following code compiles with gcc-10, but does not compile with gcc-11 any
more:

```cpp
#include <ranges>

struct coordinate_matrix {
  using index_t = size_t;
  struct convert_to_matrix_coordinate {
    index_t column_id;
    index_t operator()(index_t) { return column_id; }
  };
  using iota_view_t = decltype(std::views::iota(0, 1));
  index_t column_id;

  // does not work
  using value_type =
      decltype(std::declval<iota_view_t>() |
std::views::transform(convert_to_matrix_coordinate{column_id}));

  // does not work
  using value_type2 =
      decltype(std::views::transform(std::declval<iota_view_t>(),
convert_to_matrix_coordinate{column_id}));

  // does work
  using value_type3 =
      decltype(std::views::transform(std::declval<iota_view_t>(),
                                     ([](index_t)
                                     {
                                         return [](index_t) -> index_t
                                         {
                                             return 0;
                                         };
                                     })(column_id)));

  // does work
  using value_type4 =
      decltype(std::views::transform(std::declval<iota_view_t>(),
convert_to_matrix_coordinate{0u}));

  // does work
  using value_type5 = decltype(column_id);
};

int main()
{
    // works:
    using index_t = size_t;
    auto view = std::views::iota(0, 1);
    using iota_view_t = decltype(std::views::iota(0, 1));
    index_t column_id = 0;
    view |
std::views::transform(coordinate_matrix::convert_to_matrix_coordinate{column_id});
    using value_type = decltype(std::declval<iota_view_t>() |
                
std::views::transform(coordinate_matrix::convert_to_matrix_coordinate{column_id}));
}
```

https://godbolt.org/z/EPoP3jvab

with the following error:

```
<source>:14:97: error: invalid use of non-static data member
'coordinate_matrix::column_id'
   14 |       decltype(std::declval<iota_view_t>() |
std::views::transform(convert_to_matrix_coordinate{column_id}));
      |                                                                        
                        ^~~~~~~~~
<source>:10:11: note: declared here
   10 |   index_t column_id;
      |           ^~~~~~~~~
```

I know how to work around this, but I'm a bit confused why in some cases it
allows using column_id and some cases don't.

Thank you!

Reply via email to