public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cooky.ykooc922 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/105520] New: Ignores constraint in auto declaration with braced-init-list
Date: Sun, 08 May 2022 01:55:18 +0000 [thread overview]
Message-ID: <bug-105520-4@http.gcc.gnu.org/bugzilla/> (raw)
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
next reply other threads:[~2022-05-08 1:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-08 1:55 cooky.ykooc922 at gmail dot com [this message]
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
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-105520-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).