libstdc++: Define pretty printer for comparison categories
* python/libstdcxx/v6/printers.py (StdCmpCatPrinter): New printer. * testsuite/libstdc++-prettyprinters/cxx20.cc: New test. From-SVN: r278982
This commit is contained in:
parent
3a4cc6281b
commit
a59c50bd14
|
@ -1,5 +1,8 @@
|
||||||
2019-12-05 Jonathan Wakely <jwakely@redhat.com>
|
2019-12-05 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* python/libstdcxx/v6/printers.py (StdCmpCatPrinter): New printer.
|
||||||
|
* testsuite/libstdc++-prettyprinters/cxx20.cc: New test.
|
||||||
|
|
||||||
* include/bits/cpp_type_traits.h (__is_byte<char8_t>): Add
|
* include/bits/cpp_type_traits.h (__is_byte<char8_t>): Add
|
||||||
specialization.
|
specialization.
|
||||||
* include/std/array (operator<=>): Likewise.
|
* include/std/array (operator<=>): Likewise.
|
||||||
|
|
|
@ -1425,6 +1425,20 @@ class StdPairPrinter:
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
class StdCmpCatPrinter:
|
||||||
|
"Print a comparison category object"
|
||||||
|
|
||||||
|
def __init__ (self, typename, val):
|
||||||
|
self.typename = typename[typename.rfind(':')+1:]
|
||||||
|
self.val = val['_M_value']
|
||||||
|
|
||||||
|
def to_string (self):
|
||||||
|
if self.typename == 'strong_ordering' and self.val == 0:
|
||||||
|
name = 'equal'
|
||||||
|
else:
|
||||||
|
names = {-127:'unordered', -1:'less', 0:'equivalent', 1:'greater'}
|
||||||
|
name = names[int(self.val)]
|
||||||
|
return 'std::{}::{}'.format(self.typename, name)
|
||||||
|
|
||||||
# A "regular expression" printer which conforms to the
|
# A "regular expression" printer which conforms to the
|
||||||
# "SubPrettyPrinter" protocol from gdb.printing.
|
# "SubPrettyPrinter" protocol from gdb.printing.
|
||||||
|
@ -1928,6 +1942,11 @@ def build_libstdcxx_dictionary ():
|
||||||
libstdcxx_printer.add_version('std::',
|
libstdcxx_printer.add_version('std::',
|
||||||
'_Node_handle', StdNodeHandlePrinter)
|
'_Node_handle', StdNodeHandlePrinter)
|
||||||
|
|
||||||
|
# C++20 components
|
||||||
|
libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
|
||||||
|
libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
|
||||||
|
libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
|
||||||
|
|
||||||
# Extensions.
|
# Extensions.
|
||||||
libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
|
libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
// { dg-options "-g -O0 -std=gnu++2a" }
|
||||||
|
// { dg-do run { target c++2a } }
|
||||||
|
|
||||||
|
// Copyright (C) 2014-2019 Free Software Foundation, Inc.
|
||||||
|
//
|
||||||
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
// terms of the GNU General Public License as published by the
|
||||||
|
// Free Software Foundation; either version 3, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING3. If not see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <compare>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
std::weak_ordering operator<=>(X x) const noexcept { return i <=> x.i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
auto c1 = 1 <=> 1;
|
||||||
|
// { dg-final { note-test c1 "std::strong_ordering::equal" } }
|
||||||
|
auto c2 = 1 <=> 2;
|
||||||
|
// { dg-final { note-test c2 "std::strong_ordering::less" } }
|
||||||
|
auto c3 = 4 <=> 3;
|
||||||
|
// { dg-final { note-test c3 "std::strong_ordering::greater" } }
|
||||||
|
|
||||||
|
auto c4 = X{1} <=> X{1};
|
||||||
|
// { dg-final { note-test c4 "std::weak_ordering::equivalent" } }
|
||||||
|
auto c5 = X{2} <=> X{3};
|
||||||
|
// { dg-final { note-test c5 "std::weak_ordering::less" } }
|
||||||
|
auto c6 = X{2} <=> X{1};
|
||||||
|
// { dg-final { note-test c6 "std::weak_ordering::greater" } }
|
||||||
|
|
||||||
|
auto c7 = 0.2 <=> 0.2;
|
||||||
|
// { dg-final { note-test c7 "std::partial_ordering::equivalent" } }
|
||||||
|
auto c8 = 2.5 <=> 5.5;
|
||||||
|
// { dg-final { note-test c8 "std::partial_ordering::less" } }
|
||||||
|
auto c9 = 7.5 <=> -2.2;
|
||||||
|
// { dg-final { note-test c9 "std::partial_ordering::greater" } }
|
||||||
|
auto c10 = 0.0 <=> __builtin_nan("");
|
||||||
|
// { dg-final { note-test c10 "std::partial_ordering::unordered" } }
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
return 0; // Mark SPOT
|
||||||
|
}
|
||||||
|
|
||||||
|
// { dg-final { gdb-test SPOT } }
|
Loading…
Reference in New Issue