From 0ca22d027eccb55215bb553b66fb10637344e2e6 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 7 May 2020 11:14:51 -0400 Subject: c++: Implement P1957R2, T* to bool should be considered narrowing. This was approved in the Prague 2020 WG21 meeting so let's adjust the comment. Since it's supposed to be a DR I think we should no longer limit it to C++20. P1957R2 * typeck2.c (check_narrowing): Consider T* to bool narrowing in C++11 and up. * g++.dg/cpp0x/initlist92.C: Don't expect an error in C++20 only. --- gcc/cp/typeck2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gcc/cp/typeck2.c') diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 9e5d145..acf4414 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1040,9 +1040,10 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain, } else if (TREE_CODE (type) == BOOLEAN_TYPE && (TYPE_PTR_P (ftype) || TYPE_PTRMEM_P (ftype))) - /* This hasn't actually made it into C++20 yet, but let's add it now to get - an idea of the impact. */ - ok = (cxx_dialect < cxx2a); + /* C++20 P1957R2: converting from a pointer type or a pointer-to-member + type to bool should be considered narrowing. This is a DR so is not + limited to C++20 only. */ + ok = false; bool almost_ok = ok; if (!ok && !CONSTANT_CLASS_P (init) && (complain & tf_warning_or_error)) -- cgit v1.1