public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fchelnokov at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/103478] New: Possible regression in constexpr processing
Date: Mon, 29 Nov 2021 20:20:43 +0000	[thread overview]
Message-ID: <bug-103478-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2021-11-29 20:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 20:20 fchelnokov at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103478-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).