aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-12-08 16:44:53 -0500
committerMarek Polacek <polacek@redhat.com>2020-12-09 09:28:07 -0500
commitfe70679b80f5e6193a0976be41b68d590c7cb2f3 (patch)
treecb27930bc49389c043a7adb431c4a28d616be061 /gcc
parent33d2f41785b24ad43c5a9d52aa289e33ac838f86 (diff)
downloadgcc-fe70679b80f5e6193a0976be41b68d590c7cb2f3.zip
gcc-fe70679b80f5e6193a0976be41b68d590c7cb2f3.tar.gz
gcc-fe70679b80f5e6193a0976be41b68d590c7cb2f3.tar.bz2
c++: Fix printing of decltype(nullptr) [PR97517]
The C++ printer doesn't handle NULLPTR_TYPE, so we issue the ugly "'nullptr_type' not supported by...". Since NULLPTR_TYPE is decltype(nullptr), it seemed reasonable to handle it where we handle DECLTYPE_TYPE, that is, in the simple-type-specifier handler. gcc/cp/ChangeLog: PR c++/97517 * cxx-pretty-print.c (cxx_pretty_printer::simple_type_specifier): Handle NULLPTR_TYPE. (pp_cxx_type_specifier_seq): Likewise. (cxx_pretty_printer::type_id): Likewise. gcc/testsuite/ChangeLog: PR c++/97517 * g++.dg/diagnostic/nullptr.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/cxx-pretty-print.c6
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/nullptr.C8
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index b97f70e..e189270 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -1381,6 +1381,10 @@ cxx_pretty_printer::simple_type_specifier (tree t)
pp_cxx_right_paren (this);
break;
+ case NULLPTR_TYPE:
+ pp_cxx_ws_string (this, "std::nullptr_t");
+ break;
+
default:
c_pretty_printer::simple_type_specifier (t);
break;
@@ -1408,6 +1412,7 @@ pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
case TYPE_DECL:
case BOUND_TEMPLATE_TEMPLATE_PARM:
case DECLTYPE_TYPE:
+ case NULLPTR_TYPE:
pp_cxx_cv_qualifier_seq (pp, t);
pp->simple_type_specifier (t);
break;
@@ -1873,6 +1878,7 @@ cxx_pretty_printer::type_id (tree t)
case TYPEOF_TYPE:
case UNDERLYING_TYPE:
case DECLTYPE_TYPE:
+ case NULLPTR_TYPE:
case TEMPLATE_ID_EXPR:
case OFFSET_TYPE:
pp_cxx_type_specifier_seq (this, t);
diff --git a/gcc/testsuite/g++.dg/diagnostic/nullptr.C b/gcc/testsuite/g++.dg/diagnostic/nullptr.C
new file mode 100644
index 0000000..bc0d829
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/nullptr.C
@@ -0,0 +1,8 @@
+// PR c++/97517
+// { dg-do compile { target c++20 } }
+// Test that we print "decltype(nullptr)" correctly.
+
+template<typename T> struct Trait { static constexpr bool value = false; };
+template<typename T> concept Concept = Trait<T>::value; // { dg-message {\[with T = std::nullptr_t\]} }
+static_assert( Concept<decltype(nullptr)> ); // { dg-error "static assertion failed" }
+// { dg-message "constraints not satisfied" "" { target *-*-* } .-1 }