public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105520] New: Ignores constraint in auto declaration with braced-init-list
@ 2022-05-08 1:55 cooky.ykooc922 at gmail dot com
2022-05-08 1:58 ` [Bug c++/105520] " cooky.ykooc922 at gmail dot com
2024-04-06 21:30 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: cooky.ykooc922 at gmail dot com @ 2022-05-08 1:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105520
Bug ID: 105520
Summary: Ignores constraint in auto declaration with
braced-init-list
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cooky.ykooc922 at gmail dot com
Target Milestone: ---
>From the code snippet below:
#include <concepts>
#include <initializer_list>
template <typename T>
concept always_true = true;
template <typename T>
concept always_false = false;
template <typename>
inline constexpr bool is_init_list_v = false;
template <typename T>
inline constexpr bool is_init_list_v<std::initializer_list<T>> = true;
template <typename T>
concept not_init_list = !is_init_list_v<std::remove_cvref_t<T>>;
int main() {
always_true auto a = 10; // ok
always_true auto b = {1, 2, 3}; // ok
// always_false auto c = 10; // error as expected
// always_false auto d = {1, 2, 3}; // error as expected
not_init_list auto e = 10; // ok
not_init_list auto f = {1, 2, 3}; // no error but unexpected
// error as expected below:
// not_init_list auto g = std::initializer_list{1, 2, 3};
}
GCC accepts invalid code from `not_init_list auto f = {1, 2, 3}`, while Clang
rejects it as expected showing:
<source>:27:5: error: deduced type 'std::initializer_list<int>' does not
satisfy 'not_init_list'
not_init_list auto f = {1, 2, 3}; // no error but unexpected
^~~~~~~~~~~~~~~~~~
<source>:17:25: note: because
'!is_init_list_v<std::remove_cvref_t<initializer_list<int> > >' evaluated to
false
concept not_init_list = !is_init_list_v<std::remove_cvref_t<T>>;
^
compiler flag: -std=c++20
compiler explorer link: https://godbolt.org/z/G569rxb8f
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/105520] Ignores constraint in auto declaration with braced-init-list
2022-05-08 1:55 [Bug c++/105520] New: Ignores constraint in auto declaration with braced-init-list cooky.ykooc922 at gmail dot com
@ 2022-05-08 1:58 ` cooky.ykooc922 at gmail dot com
2024-04-06 21:30 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: cooky.ykooc922 at gmail dot com @ 2022-05-08 1:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105520
Desmond Gold <cooky.ykooc922 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|12.0 |10.0
--- Comment #1 from Desmond Gold <cooky.ykooc922 at gmail dot com> ---
GCC 10.1 to GCC trunk accept this invalid code
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/105520] Ignores constraint in auto declaration with braced-init-list
2022-05-08 1:55 [Bug c++/105520] New: Ignores constraint in auto declaration with braced-init-list cooky.ykooc922 at gmail dot com
2022-05-08 1:58 ` [Bug c++/105520] " cooky.ykooc922 at gmail dot com
@ 2024-04-06 21:30 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-06 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105520
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Blocks| |67491
Ever confirmed|0 |1
Last reconfirmed| |2024-04-06
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
This works as expected, in that we are getting the correct type for auto here:
```
#include <concepts>
#include <initializer_list>
template <typename T>
concept always_true = true;
template <typename T>
concept always_false = false;
template <typename>
inline constexpr bool is_init_list_v = false;
template <typename T>
inline constexpr bool is_init_list_v<std::initializer_list<T>> = true;
template <typename T>
concept not_init_list = !is_init_list_v<std::remove_cvref_t<T>>;
template <typename T>
inline constexpr bool not_init_list1 = !is_init_list_v<std::remove_cvref_t<T>>;
int main() {
auto f = {1, 2, 3};
static_assert(!not_init_list<decltype(f)>);
static_assert(!not_init_list1<decltype(f)>);
}
```
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67491
[Bug 67491] [meta-bug] concepts issues
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-06 21:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-08 1:55 [Bug c++/105520] New: Ignores constraint in auto declaration with braced-init-list cooky.ykooc922 at gmail dot com
2022-05-08 1:58 ` [Bug c++/105520] " cooky.ykooc922 at gmail dot com
2024-04-06 21:30 ` pinskia 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).