diff options
author | Marek Polacek <polacek@redhat.com> | 2020-05-15 10:59:01 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-05-18 15:50:12 -0400 |
commit | 100fdb1f09b484ef100b638b28a260857d85f9dd (patch) | |
tree | 843472f613abf74a1cb577886e164f7e1550a5c5 /gcc | |
parent | 642dc602f89b2c11d5d833a52f37b04427a27cab (diff) | |
download | gcc-100fdb1f09b484ef100b638b28a260857d85f9dd.zip gcc-100fdb1f09b484ef100b638b28a260857d85f9dd.tar.gz gcc-100fdb1f09b484ef100b638b28a260857d85f9dd.tar.bz2 |
c++: Don't add built-in operator for ++ on bool.
This feels extremely obscure but at least it's an opportunity to fix the
comments. P0002R1 removed deprecated operator++(bool) in C++17 so let's
avoid adding a builtin overload candidate for ++ when the type is bool.
* call.c (add_builtin_candidate): Don't create a builtin overload
candidate for ++ when type is bool in C++17.
* g++.dg/overload/builtin5.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/call.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/overload/builtin5.C | 21 |
4 files changed, 42 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 98c2823..e9cd3eb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,4 +1,9 @@ -2020-05-17 Marek Polacek <polacek@redhat.com> +2020-05-18 Marek Polacek <polacek@redhat.com> + + * call.c (add_builtin_candidate): Don't create a builtin overload + candidate for ++ when type is bool in C++17. + +2020-05-18 Marek Polacek <polacek@redhat.com> * cfns.h: Regenerated. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index c587197..b96bc06 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2672,19 +2672,19 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, switch (code) { -/* 4 For every pair T, VQ), where T is an arithmetic or enumeration type, +/* 4 For every pair (T, VQ), where T is an arithmetic type other than bool, and VQ is either volatile or empty, there exist candidate operator functions of the form VQ T& operator++(VQ T&); T operator++(VQ T&, int); - 5 For every pair T, VQ), where T is an enumeration type or an arithmetic - type other than bool, and VQ is either volatile or empty, there exist - candidate operator functions of the form + 5 For every pair (T, VQ), where T is an arithmetic type other than bool, + and VQ is either volatile or empty, there exist candidate operator + functions of the form VQ T& operator--(VQ T&); T operator--(VQ T&, int); - 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified - complete object type, and VQ is either volatile or empty, there exist - candidate operator functions of the form + 6 For every pair (T, VQ), where T is a cv-qualified or cv-unqualified object + type, and VQ is either volatile or empty, there exist candidate operator + functions of the form T*VQ& operator++(T*VQ&); T*VQ& operator--(T*VQ&); T* operator++(T*VQ&, int); @@ -2697,6 +2697,10 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, /* FALLTHRU */ case POSTINCREMENT_EXPR: case PREINCREMENT_EXPR: + /* P0002R1, Remove deprecated operator++(bool) added "other than bool" + to p4. */ + if (TREE_CODE (type1) == BOOLEAN_TYPE && cxx_dialect >= cxx17) + return; if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1)) { type1 = build_reference_type (type1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ad5b28d..0b5e1d3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-05-18 Marek Polacek <polacek@redhat.com> + + * g++.dg/overload/builtin5.C: New test. + 2020-05-18 Doug Rupp <rupp@adacore.com> * gcc.target/powerpc/pr71763.c: Require powerpc_vsx_ok. diff --git a/gcc/testsuite/g++.dg/overload/builtin5.C b/gcc/testsuite/g++.dg/overload/builtin5.C new file mode 100644 index 0000000..a30251d --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/builtin5.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++17 } } +// Don't add built-in operator for ++ on bool. + +template<typename T> +struct S { operator T&(); }; + +template<int> void +foo (S<bool>& s) +{ + --s; // { dg-error "no match for" } + ++s; // { dg-error "no match for" } + s++; // { dg-error "declared for postfix" } + s--; // { dg-error "declared for postfix" } +} + +void +bar () +{ + S<bool> s; + foo<0> (s); +} |