public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979]
@ 2023-05-04 16:33 Patrick Palka
  2023-05-04 17:57 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-05-04 16:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

	PR c++/85979

gcc/cp/ChangeLog:

	* cxx-pretty-print.cc (cxx_pretty_printer::unary_expression)
	<case ALIGNOF_EXPR>: Consider ALIGNOF_EXPR_STD_P.
	* error.cc (dump_expr) <case ALIGNOF_EXPR>: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/diagnostic/alignof4.C: New test.
---
 gcc/cp/cxx-pretty-print.cc                 |  7 ++++++-
 gcc/cp/error.cc                            |  7 +++----
 gcc/testsuite/g++.dg/diagnostic/alignof4.C | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/alignof4.C

diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index 4cda27f2b30..4e9de3eff87 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -844,7 +844,12 @@ cxx_pretty_printer::unary_expression (tree t)
       /* Fall through  */
 
     case ALIGNOF_EXPR:
-      pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
+      if (code == SIZEOF_EXPR)
+	pp_cxx_ws_string (this, "sizeof");
+      else if (ALIGNOF_EXPR_STD_P (t))
+	pp_cxx_ws_string (this, "alignof");
+      else
+	pp_cxx_ws_string (this, "__alignof__");
       pp_cxx_whitespace (this);
       if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
 	{
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index a5d888926a6..7865f6518fc 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -2840,11 +2840,10 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
     case ALIGNOF_EXPR:
       if (TREE_CODE (t) == SIZEOF_EXPR)
 	pp_cxx_ws_string (pp, "sizeof");
+      else if (ALIGNOF_EXPR_STD_P (t))
+	pp_cxx_ws_string (pp, "alignof");
       else
-	{
-	  gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR);
-	  pp_cxx_ws_string (pp, "__alignof__");
-	}
+	pp_cxx_ws_string (pp, "__alignof__");
       op = TREE_OPERAND (t, 0);
       if (PACK_EXPANSION_P (op))
 	{
diff --git a/gcc/testsuite/g++.dg/diagnostic/alignof4.C b/gcc/testsuite/g++.dg/diagnostic/alignof4.C
new file mode 100644
index 00000000000..f6fc5c31563
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/alignof4.C
@@ -0,0 +1,21 @@
+// PR c++/85979
+// { dg-do compile { target c++11 } }
+
+template<int N> struct A { };
+
+template<class T>
+void f(A<alignof(T)>) { }
+
+#if __cpp_concepts
+template<class T>
+void g() requires (alignof(T) == 0);
+#endif
+
+int main() {
+  f<int>(); // { dg-error "no match" }
+#if __cpp_concepts
+  g<int>(); // { dg-error "no match" "" { target c++20 } }
+#endif
+}
+
+// { dg-bogus "__alignof__" "" { target *-*-* } 0 }
-- 
2.40.1.476.g69c786637d


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979]
  2023-05-04 16:33 [PATCH] c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979] Patrick Palka
@ 2023-05-04 17:57 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-05-04 17:57 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 5/4/23 12:33, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> 	PR c++/85979
> 
> gcc/cp/ChangeLog:
> 
> 	* cxx-pretty-print.cc (cxx_pretty_printer::unary_expression)
> 	<case ALIGNOF_EXPR>: Consider ALIGNOF_EXPR_STD_P.
> 	* error.cc (dump_expr) <case ALIGNOF_EXPR>: Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/diagnostic/alignof4.C: New test.
> ---
>   gcc/cp/cxx-pretty-print.cc                 |  7 ++++++-
>   gcc/cp/error.cc                            |  7 +++----
>   gcc/testsuite/g++.dg/diagnostic/alignof4.C | 21 +++++++++++++++++++++
>   3 files changed, 30 insertions(+), 5 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/diagnostic/alignof4.C
> 
> diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
> index 4cda27f2b30..4e9de3eff87 100644
> --- a/gcc/cp/cxx-pretty-print.cc
> +++ b/gcc/cp/cxx-pretty-print.cc
> @@ -844,7 +844,12 @@ cxx_pretty_printer::unary_expression (tree t)
>         /* Fall through  */
>   
>       case ALIGNOF_EXPR:
> -      pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
> +      if (code == SIZEOF_EXPR)
> +	pp_cxx_ws_string (this, "sizeof");
> +      else if (ALIGNOF_EXPR_STD_P (t))
> +	pp_cxx_ws_string (this, "alignof");
> +      else
> +	pp_cxx_ws_string (this, "__alignof__");
>         pp_cxx_whitespace (this);
>         if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
>   	{
> diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
> index a5d888926a6..7865f6518fc 100644
> --- a/gcc/cp/error.cc
> +++ b/gcc/cp/error.cc
> @@ -2840,11 +2840,10 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
>       case ALIGNOF_EXPR:
>         if (TREE_CODE (t) == SIZEOF_EXPR)
>   	pp_cxx_ws_string (pp, "sizeof");
> +      else if (ALIGNOF_EXPR_STD_P (t))
> +	pp_cxx_ws_string (pp, "alignof");
>         else
> -	{
> -	  gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR);
> -	  pp_cxx_ws_string (pp, "__alignof__");
> -	}
> +	pp_cxx_ws_string (pp, "__alignof__");
>         op = TREE_OPERAND (t, 0);
>         if (PACK_EXPANSION_P (op))
>   	{
> diff --git a/gcc/testsuite/g++.dg/diagnostic/alignof4.C b/gcc/testsuite/g++.dg/diagnostic/alignof4.C
> new file mode 100644
> index 00000000000..f6fc5c31563
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/diagnostic/alignof4.C
> @@ -0,0 +1,21 @@
> +// PR c++/85979
> +// { dg-do compile { target c++11 } }
> +
> +template<int N> struct A { };
> +
> +template<class T>
> +void f(A<alignof(T)>) { }
> +
> +#if __cpp_concepts
> +template<class T>
> +void g() requires (alignof(T) == 0);
> +#endif
> +
> +int main() {
> +  f<int>(); // { dg-error "no match" }
> +#if __cpp_concepts
> +  g<int>(); // { dg-error "no match" "" { target c++20 } }
> +#endif
> +}
> +
> +// { dg-bogus "__alignof__" "" { target *-*-* } 0 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-04 17:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 16:33 [PATCH] c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979] Patrick Palka
2023-05-04 17:57 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).