diff options
author | Jason Merrill <jason@redhat.com> | 2019-11-10 15:30:03 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2019-11-10 15:30:03 -0500 |
commit | 2806ecbdc8054ef9f3968577806b007baefad4e6 (patch) | |
tree | 144d7a35712fc76f3d1deecbc1d6c139f4bf098d | |
parent | 0313a84a2faa8f685eb489fa787f1ea969f68560 (diff) | |
download | gcc-2806ecbdc8054ef9f3968577806b007baefad4e6.zip gcc-2806ecbdc8054ef9f3968577806b007baefad4e6.tar.gz gcc-2806ecbdc8054ef9f3968577806b007baefad4e6.tar.bz2 |
Implement D1957R0, T* to bool should be considered narrowing.
This paper was delayed until the February meeting in Prague so that we could
get a better idea of what the impact on existing code would actually be. To
that end, I'm implementing it now.
* typeck2.c (check_narrowing): Treat pointer->bool as a narrowing
conversion with -std=c++2a.
From-SVN: r278026
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck2.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist92.C | 51 |
3 files changed, 24 insertions, 38 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 170ce30..23576ec 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-11-10 Jason Merrill <jason@redhat.com> + + Implement D1957R0, T* to bool should be considered narrowing. + * typeck2.c (check_narrowing): Treat pointer->bool as a narrowing + conversion with -std=c++2a. + 2019-11-08 Marek Polacek <polacek@redhat.com> PR c++/92215 - flawed diagnostic for bit-field with non-integral type. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 7884d42..9fb36fd 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1018,6 +1018,11 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain, ok = true; } } + 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); bool almost_ok = ok; if (!ok && !CONSTANT_CLASS_P (init) && (complain & tf_warning_or_error)) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist92.C b/gcc/testsuite/g++.dg/cpp0x/initlist92.C index 81a6318..319264a 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist92.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist92.C @@ -1,26 +1,13 @@ // PR c++/64665, DR 1467 -// { dg-do run { target c++11 } } +// { dg-do compile { target c++11 } } #include <string> -#include <cassert> -bool Test1(bool) -{ - return true; -} -bool Test1(std::string) -{ - return false; -} +bool Test1(bool); +bool Test1(std::string) = delete; -bool Test2(int) -{ - return false; -} -bool Test2(std::initializer_list<int>) -{ - return true; -} +bool Test2(int) = delete; +bool Test2(std::initializer_list<int>); struct S { @@ -28,28 +15,16 @@ struct S private: int a; }; -bool Test3(int) -{ - return true; -} -bool Test3(S) -{ - return false; -} +bool Test3(int); +bool Test3(S) = delete; -bool Test4(bool) -{ - return false; -} -bool Test4(std::initializer_list<std::string>) -{ - return true; -} +bool Test4(bool) = delete; +bool Test4(std::initializer_list<std::string>); int main () { - assert ( Test1({"false"}) ); - assert ( Test2({123}) ); - assert ( Test3({456}) ); - assert ( Test4({"false"}) ); + ( Test1({"false"}) ); // { dg-error "narrowing" "" { target c++2a } } + ( Test2({123}) ); + ( Test3({456}) ); + ( Test4({"false"}) ); } |