diff mbox series

c++: Fix printing of decltype(nullptr) [PR97517]

Message ID 20201208225318.2368612-1-polacek@redhat.com
State New
Headers show
Series c++: Fix printing of decltype(nullptr) [PR97517] | expand

Commit Message

Marek Polacek Dec. 8, 2020, 10:53 p.m. UTC
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.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

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.
---
 gcc/cp/cxx-pretty-print.c                 | 6 ++++++
 gcc/testsuite/g++.dg/diagnostic/nullptr.C | 8 ++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/nullptr.C


base-commit: 0221c656bbe5b4ab54e784df3b109c60cb27e5b6

Comments

Jason Merrill Dec. 9, 2020, 5:40 a.m. UTC | #1
On 12/8/20 5:53 PM, Marek Polacek wrote:
> 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.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> 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.
> ---
>   gcc/cp/cxx-pretty-print.c                 | 6 ++++++
>   gcc/testsuite/g++.dg/diagnostic/nullptr.C | 8 ++++++++
>   2 files changed, 14 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/diagnostic/nullptr.C
> 
> diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
> index b97f70e2bd0..02721e88a5b 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, "nullptr_t");

Let's say std::nullptr_t.  OK with that change.

> +      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 00000000000..2c9e5a80bd5
> --- /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 = nullptr_t\]} }
> +static_assert( Concept<decltype(nullptr)> ); // { dg-error "static assertion failed" }
> +// { dg-message "constraints not satisfied" "" { target *-*-* } .-1 }
> 
> base-commit: 0221c656bbe5b4ab54e784df3b109c60cb27e5b6
>
diff mbox series

Patch

diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index b97f70e2bd0..02721e88a5b 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, "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 00000000000..2c9e5a80bd5
--- /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 = nullptr_t\]} }
+static_assert( Concept<decltype(nullptr)> ); // { dg-error "static assertion failed" }
+// { dg-message "constraints not satisfied" "" { target *-*-* } .-1 }