public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Improve printing of base classes [PR110745]
@ 2023-07-19 21:51 Marek Polacek
  2023-07-19 21:56 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2023-07-19 21:51 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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

-- >8 --

This patch changes

  warning: missing initializer for member 'D::<anonymous>' [-Wmissing-field-initializers]

to

  warning: missing initializer for member 'D::B' [-Wmissing-field-initializers]

	PR c++/110745

gcc/cp/ChangeLog:

	* error.cc (dump_simple_decl): Print base class name.

gcc/testsuite/ChangeLog:

	* g++.dg/diagnostic/base.C: New test.
---
 gcc/cp/error.cc                        |  2 ++
 gcc/testsuite/g++.dg/diagnostic/base.C | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/base.C

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 31319aa9e87..8a5219a68a1 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -1177,6 +1177,8 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
     }
   else if (DECL_DECOMPOSITION_P (t))
     pp_string (pp, M_("<structured bindings>"));
+  else if (TREE_CODE (t) == FIELD_DECL && DECL_FIELD_IS_BASE (t))
+    dump_type (pp, TREE_TYPE (t), flags);
   else
     pp_string (pp, M_("<anonymous>"));
 
diff --git a/gcc/testsuite/g++.dg/diagnostic/base.C b/gcc/testsuite/g++.dg/diagnostic/base.C
new file mode 100644
index 00000000000..1540414072e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/base.C
@@ -0,0 +1,16 @@
+// PR c++/110745
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wmissing-field-initializers" }
+
+struct B { int i; };
+struct D : B {
+    int x;
+    int y;
+};
+
+int
+main ()
+{
+  D d = {.x=1, .y=2}; // { dg-warning "missing initializer for member .D::B." }
+  (void)d;
+}

base-commit: b1ae46bdd19fc2aaea41bc894168bdaf4799be80
-- 
2.41.0


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

* Re: [PATCH] c++: Improve printing of base classes [PR110745]
  2023-07-19 21:51 [PATCH] c++: Improve printing of base classes [PR110745] Marek Polacek
@ 2023-07-19 21:56 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-07-19 21:56 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 7/19/23 17:51, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK, thanks.

> -- >8 --
> 
> This patch changes
> 
>    warning: missing initializer for member 'D::<anonymous>' [-Wmissing-field-initializers]
> 
> to
> 
>    warning: missing initializer for member 'D::B' [-Wmissing-field-initializers]
> 
> 	PR c++/110745
> 
> gcc/cp/ChangeLog:
> 
> 	* error.cc (dump_simple_decl): Print base class name.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/diagnostic/base.C: New test.
> ---
>   gcc/cp/error.cc                        |  2 ++
>   gcc/testsuite/g++.dg/diagnostic/base.C | 16 ++++++++++++++++
>   2 files changed, 18 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/diagnostic/base.C
> 
> diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
> index 31319aa9e87..8a5219a68a1 100644
> --- a/gcc/cp/error.cc
> +++ b/gcc/cp/error.cc
> @@ -1177,6 +1177,8 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
>       }
>     else if (DECL_DECOMPOSITION_P (t))
>       pp_string (pp, M_("<structured bindings>"));
> +  else if (TREE_CODE (t) == FIELD_DECL && DECL_FIELD_IS_BASE (t))
> +    dump_type (pp, TREE_TYPE (t), flags);
>     else
>       pp_string (pp, M_("<anonymous>"));
>   
> diff --git a/gcc/testsuite/g++.dg/diagnostic/base.C b/gcc/testsuite/g++.dg/diagnostic/base.C
> new file mode 100644
> index 00000000000..1540414072e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/diagnostic/base.C
> @@ -0,0 +1,16 @@
> +// PR c++/110745
> +// { dg-do compile { target c++17 } }
> +// { dg-options "-Wmissing-field-initializers" }
> +
> +struct B { int i; };
> +struct D : B {
> +    int x;
> +    int y;
> +};
> +
> +int
> +main ()
> +{
> +  D d = {.x=1, .y=2}; // { dg-warning "missing initializer for member .D::B." }
> +  (void)d;
> +}
> 
> base-commit: b1ae46bdd19fc2aaea41bc894168bdaf4799be80


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

end of thread, other threads:[~2023-07-19 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 21:51 [PATCH] c++: Improve printing of base classes [PR110745] Marek Polacek
2023-07-19 21:56 ` 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).