public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103478] New: Possible regression in constexpr processing
@ 2021-11-29 20:20 fchelnokov at gmail dot com
  2021-11-29 20:25 ` [Bug c++/103478] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fchelnokov at gmail dot com @ 2021-11-29 20:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103478
           Summary: Possible regression in constexpr processing
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following code is accepted by GCC 9.4 and rejected by GCC 10.1:
```
#include <array>
using namespace std;

template<size_t N> using string_literal_t = char[N];

template<class T> struct StrSize; ///< metafunction to get the size of string
literal alikes 

/// specialize StrSize for string literals
template<size_t N>
struct StrSize <string_literal_t<N>>{ static constexpr size_t value = N-1; };

/// template variable, just for convenience
template <class T>
constexpr size_t str_size = StrSize<T>::value;

/// now do the same but with constexpr function
template<class T>
constexpr auto strsize(const T&) noexcept-> decltype(str_size<T>) {
   return str_size<T>;
}

template<class S, size_t... Is>
constexpr auto test_helper(const S& s, index_sequence<Is...>) noexcept->
array<char, str_size<S>> {
   return {s[Is]...};
}

template<class S>
constexpr auto test(const S& s) noexcept-> decltype(auto) {
   return test_helper(s, make_index_sequence<strsize(s)>{});
}

auto main()-> int {
   static_assert(strsize("qwe") == 3, "");
   static_assert(noexcept(test("qwe")) == true, "");

   return 0;
}
```
Demo: https://gcc.godbolt.org/z/43TcY485x

Could you please check whether it is a regression?

Related discussion: https://stackoverflow.com/q/43072361/7325599

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-01  2:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 20:20 [Bug c++/103478] New: Possible regression in constexpr processing fchelnokov at gmail dot com
2021-11-29 20:25 ` [Bug c++/103478] " pinskia at gcc dot gnu.org
2021-11-29 20:27 ` pinskia at gcc dot gnu.org
2021-11-30  7:05 ` rguenth at gcc dot gnu.org
2021-11-30 14:23 ` marxin at gcc dot gnu.org
2021-12-01  2:24 ` [Bug c++/103478] More explanation for error on constexpr function parameter used in a constant expression jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).