Bug 110745 - Improve printing of base classes
Summary: Improve printing of base classes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2023-07-19 20:09 UTC by Marek Polacek
Modified: 2023-07-19 22:22 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-07-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2023-07-19 20:09:13 UTC
Prompted by <https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624964.html>:

struct B { int i; };
struct D : B {
    int x;
    int y;
};

int
main ()
{
  D d = {.x=1, .y=2};
  (void)d;
}

$ ./cc1plus -quiet q.C -Wmissing-field-initializers
q.C: In function ‘int main()’:
q.C:10:20: warning: missing initializer for member 'D::<anonymous>' [-Wmissing-field-initializers]
   10 |   D d = {.x=1, .y=2};
      |                    ^

We should be able to say 'D::B' instead.
Comment 1 GCC Commits 2023-07-19 22:22:28 UTC
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:e92ca8d3b4cab96a9f79466b5158381cb3103f9d

commit r14-2659-ge92ca8d3b4cab96a9f79466b5158381cb3103f9d
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Jul 19 16:50:00 2023 -0400

    c++: Improve printing of base classes [PR110745]
    
    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.
Comment 2 Marek Polacek 2023-07-19 22:22:55 UTC
Fixed.