+2019-11-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/92215 - flawed diagnostic for bit-field with non-integral type.
+ * parser.c (cp_parser_member_declaration): Add a diagnostic for
+ bit-fields with non-integral types.
+
2019-11-08 Jakub Jelinek <jakub@redhat.com>
* init.c (build_vec_delete_1): Fix a comment typo - mist -> must.
else
initializer = cp_parser_initializer (parser, &x, &x);
}
+ /* Detect invalid bit-field cases such as
+
+ int *p : 4;
+ int &&r : 3;
+
+ and similar. */
+ else if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)
+ /* If there were no type specifiers, it was a
+ constructor. */
+ && decl_specifiers.any_type_specifiers_p)
+ {
+ /* This is called for a decent diagnostic only. */
+ tree d = grokdeclarator (declarator, &decl_specifiers,
+ BITFIELD, /*initialized=*/false,
+ &attributes);
+ error_at (DECL_SOURCE_LOCATION (d),
+ "bit-field %qD has non-integral type %qT",
+ d, TREE_TYPE (d));
+ cp_parser_skip_to_end_of_statement (parser);
+ /* Avoid "extra ;" pedwarns. */
+ if (cp_lexer_next_token_is (parser->lexer,
+ CPP_SEMICOLON))
+ cp_lexer_consume_token (parser->lexer);
+ goto out;
+ }
/* Otherwise, there is no initializer. */
else
initializer = NULL_TREE;
+2019-11-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/92215 - flawed diagnostic for bit-field with non-integral type.
+ * g++.dg/diagnostic/bitfld4.C: New test.
+
2019-11-08 Marek Polacek <polacek@redhat.com>
PR c++/92058 - constinit malfunction in static data member.
--- /dev/null
+// PR c++/92215 - flawed diagnostic for bit-field with non-integral type.
+// { dg-do compile { target c++11 } }
+
+struct S {
+ int *f1 : 3; // { dg-error "bit-field .f1. has non-integral type .int\\*." }
+ int &f2 : 3; // { dg-error "bit-field .f2. has non-integral type .int&." }
+ int &&f3 : 3; // { dg-error "bit-field .f3. has non-integral type .int&&." }
+ int f4[1] : 3; // { dg-error "bit-field .f4. has non-integral type .int \\\[1\\\]." }
+ int *f5 __attribute__((deprecated)) : 3; // { dg-error "bit-field .f5. has non-integral type .int\\*." }
+ int f6[1] __attribute__((deprecated)) : 3; // { dg-error "bit-field .f6. has non-integral type .int \\\[1\\\]." }
+ int &f7 __attribute__((deprecated)): 3; // { dg-error "bit-field .f7. has non-integral type .int&." }
+ int ****: 3; // { dg-error "expected" }
+ int *f9[1] : 3; // { dg-error "bit-field .f9. has non-integral type .int\\* \\\[1\\\]." }
+ int (*f10)() : 3; // { dg-error "bit-field .f10. has non-integral type .int \\(\\*\\)\\(\\)." }
+ int [][2] : 3; // { dg-error "expected" }
+};