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

            Bug ID: 94498
           Summary: std::basic_string_view::copy not qualified constexpr
                    in c++2a
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: takechi101010 at gmail dot com
  Target Milestone: ---

Following code fails to compile:
```c++
#include <iostream>
#include <fstream>
#include <string_view>

constexpr size_t copy(std::string_view str, char* dst) {
    return str.copy(dst, 1);
}

int main() {
    std::string_view str = "aaaa";
    char a[2];
    copy(str, a);
    std::cout << a[0] << std::endl;
}
```

with:

```
prog.cc: In function 'constexpr size_t copy(std::string_view, char*)':
prog.cc:6:20: error: call to non-'constexpr' function
'std::basic_string_view<_CharT, _Traits>::size_type
std::basic_string_view<_CharT, _Traits>::copy(_CharT*,
std::basic_string_view<_CharT, _Traits>::size_type,
std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char;
_Traits = std::char_traits<char>; std::basic_string_view<_CharT,
_Traits>::size_type = long unsigned int]'
    6 |     return str.copy(dst, 1);
      |            ~~~~~~~~^~~~~~~~
```

https://wandbox.org/permlink/pNreqN8l5RPdPlTZ

Reply via email to