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

            Bug ID: 103951
           Summary: [C++2b] string_view range constructor, "exception
                    specification ... depends on itself"
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamsupermouse at mail dot ru
  Target Milestone: ---

Following code compiles with -std=c++20 and earlier, but fails with -std=c++2b,
in both GCC and Clang with libstdc++, with similar errors.

I've tested both on GCC 11.2 and on trunk 12.0.0 20220109 at gcc.godbolt.org.

    #include <string_view>

    struct Iter
    {
        Iter() {}
        Iter(std::string_view) {} // Adding `explicit` fixes the error

        Iter begin() const
        {
            return *this;
        }
    };

It's supposed to be used as `for (auto x : Iter(...))`, exactly like
`fs::directory_iterator`, but I've removed `end()` and overloaded operators for
brevity.

The error message boils down to `return *this` considering the `string_view`
constructor, which checks `Iter` against `contiguous_range`, which circularly
checks `begin()`.

I'm not sure if the code is legal or not, but the error is very unintuitive, so
I decided to report it. I would expect this to be a soft SFINAE failure.

Reply via email to