aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-05-07 11:14:51 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-07 13:41:33 -0400
commit0ca22d027eccb55215bb553b66fb10637344e2e6 (patch)
treeacb943efac6d5545437e32535fd309de96a75fb8 /gcc
parentb9250b3cb91b667cd67943e0fac94bf39ac089a8 (diff)
downloadgcc-0ca22d027eccb55215bb553b66fb10637344e2e6.zip
gcc-0ca22d027eccb55215bb553b66fb10637344e2e6.tar.gz
gcc-0ca22d027eccb55215bb553b66fb10637344e2e6.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck2.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist92.C2
4 files changed, 16 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c60b8bf..312f1ab 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2020-05-07 Marek Polacek <polacek@redhat.com>
+ P1957R2
+ * typeck2.c (check_narrowing): Consider T* to bool narrowing
+ in C++11 and up.
+
+2020-05-07 Marek Polacek <polacek@redhat.com>
+
* decl.c (grok_op_properties): Fix spelling of non-static.
* typeck.c (build_class_member_access_expr): Likewise.
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))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 944c1e8..d14d534 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-07 Marek Polacek <polacek@redhat.com>
+
+ P1957R2
+ * g++.dg/cpp0x/initlist92.C: Don't expect an error in C++20 only.
+
2020-05-07 Manfred Schwarb <manfred99@gmx.ch>
* gcc.dg/20050121-1.c: Fix broken dg directives.
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist92.C b/gcc/testsuite/g++.dg/cpp0x/initlist92.C
index 319264a..213b192 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist92.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist92.C
@@ -23,7 +23,7 @@ bool Test4(std::initializer_list<std::string>);
int main ()
{
- ( Test1({"false"}) ); // { dg-error "narrowing" "" { target c++2a } }
+ ( Test1({"false"}) ); // { dg-error "narrowing" }
( Test2({123}) );
( Test3({456}) );
( Test4({"false"}) );