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
* [Bug c++/103478] Possible regression in constexpr processing
2021-11-29 20:20 [Bug c++/103478] New: Possible regression in constexpr processing fchelnokov at gmail dot com
@ 2021-11-29 20:25 ` pinskia at gcc dot gnu.org
2021-11-29 20:27 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29 20:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103478
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
arguments to constexpr functions are not valid template arguments.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103478] Possible regression in constexpr processing
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29 20:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103478
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
That is:
template<class S>
constexpr auto test(const S& s) noexcept-> decltype(auto) {
return test_helper(s, make_index_sequence<strsize(s)>{});
}
Is invalid.
Clang rejects it too but with a better diagnostic:
<source>:30:46: error: non-type template argument is not a constant expression
return test_helper(s, make_index_sequence<strsize(s)>{});
^~~~~~~~~~
<source>:35:27: note: in instantiation of function template specialization
'test<char[4]>' requested here
static_assert(noexcept(test("qwe")) == true, "");
^
<source>:30:54: note: function parameter 's' with unknown value cannot be used
in a constant expression
return test_helper(s, make_index_sequence<strsize(s)>{});
^
<source>:29:30: note: declared here
constexpr auto test(const S& s) noexcept-> decltype(auto) {
^
So I will leave it open for a better error message request.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103478] Possible regression in constexpr processing
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
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-30 7:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103478
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-11-30
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103478] Possible regression in constexpr processing
2021-11-29 20:20 [Bug c++/103478] New: Possible regression in constexpr processing fchelnokov at gmail dot com
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-11-30 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103478
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org,
| |marxin at gcc dot gnu.org
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r10-6417-g87fbd5347b338830.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103478] More explanation for error on constexpr function parameter used in a constant expression
2021-11-29 20:20 [Bug c++/103478] New: Possible regression in constexpr processing fchelnokov at gmail dot com
` (3 preceding siblings ...)
2021-11-30 14:23 ` marxin at gcc dot gnu.org
@ 2021-12-01 2:24 ` jason at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-01 2:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103478
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Summary|Possible regression in |More explanation for error
|constexpr processing |on constexpr function
| |parameter used in a
| |constant expression
^ 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).