]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Improve printing of base classes [PR110745]
authorMarek Polacek <polacek@redhat.com>
Wed, 19 Jul 2023 20:50:00 +0000 (16:50 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 19 Jul 2023 22:22:09 +0000 (18:22 -0400)
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
gcc/testsuite/g++.dg/diagnostic/base.C [new file with mode: 0644]

index 31319aa9e87dcb0559520707d463f7ad051eff38..8a5219a68a1931af62fbda1a2ccfe6d80a953a28 100644 (file)
@@ -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 (file)
index 0000000..1540414
--- /dev/null
@@ -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;
+}