PR c++/92215 - flawed diagnostic for bit-field with non-integral type.
commit65471f09e9f0b192927ca980c2676044209adbba
authorMarek Polacek <polacek@redhat.com>
Fri, 8 Nov 2019 21:48:47 +0000 (8 21:48 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 8 Nov 2019 21:48:47 +0000 (8 21:48 +0000)
tree6d694656d3c7fcabd191af27068af367ce3d3dd9
parenta2dbbda892ac9e26fd7ebf6167363c58e5ed726b
PR c++/92215 - flawed diagnostic for bit-field with non-integral type.

I noticed that for code like

  struct S {
    int *foo : 3;
  };

we generate nonsensical

  r.C:2:8: error: function definition does not declare parameters
      2 |   int *foo : 3;

It talks about a function because after parsing the declspecs of 'foo' we don't
see either ':' or "name :", so we think it's not a bit-field decl.  So we parse
the declarator and since a ctor-initializer begins with a ':', we try to parse
it as a function body, generating the awful diagnostic.  With this patch, we
issue:

  r.C:2:8: error: bit-field ‘foo’ has non-integral type ‘int*’
      2 |   int *foo : 3;

* parser.c (cp_parser_member_declaration): Add a diagnostic for
bit-fields with non-integral types.

* g++.dg/diagnostic/bitfld4.C: New test.

From-SVN: r277991
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/bitfld4.C [new file with mode: 0644]