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