From: Paolo Carlini Date: Thu, 6 Dec 2018 23:20:16 +0000 (+0000) Subject: class.c (check_bitfield_decl): In error message about non-integral type print the... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c1eaf67e9a4a1a63ff26b24c4b1f9f1a7c58bc4;p=gcc.git class.c (check_bitfield_decl): In error message about non-integral type print the type itself too. /cp 2018-12-06 Paolo Carlini * class.c (check_bitfield_decl): In error message about non-integral type print the type itself too. * decl.c (grokdeclarator): Do not ICE on unnamed bit-fields declared friends; when calling build_decl for a FIELD_DECL possibly pass the declarator->id_loc. /testsuite 2018-12-06 Paolo Carlini * g++.dg/parse/bitfield7.C: New. * g++.dg/other/bitfield2.C: Check location and type. * g++.dg/parse/bitfield1.C: Likewise. * g++.dg/parse/bitfield2.C: Likewise. From-SVN: r266876 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e092c4490f5..707058064e0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-12-06 Paolo Carlini + + * class.c (check_bitfield_decl): In error message about non-integral + type print the type itself too. + * decl.c (grokdeclarator): Do not ICE on unnamed bit-fields declared + friends; when calling build_decl for a FIELD_DECL possibly pass the + declarator->id_loc. + 2018-12-06 Alexandre Oliva PR c++/86747 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 9c175f85cf6..1bcb146fbb6 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3218,7 +3218,8 @@ check_bitfield_decl (tree field) /* Detect invalid bit-field type. */ if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type)) { - error ("bit-field %q+#D with non-integral type", field); + error_at (DECL_SOURCE_LOCATION (field), + "bit-field %q#D with non-integral type %qT", field, type); w = error_mark_node; } else diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e662f63bb0f..832e73a64dc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12446,9 +12446,13 @@ grokdeclarator (const cp_declarator *declarator, { if (friendp) { - error_at (declarator->id_loc, - "%qE is neither function nor member function; " - "cannot be declared friend", unqualified_id); + if (unqualified_id && declarator) + error_at (declarator->id_loc, + "%qE is neither function nor member function; " + "cannot be declared friend", unqualified_id); + else + error ("unnamed field is neither function nor member " + "function; cannot be declared friend"); return error_mark_node; } decl = NULL_TREE; @@ -12483,14 +12487,13 @@ grokdeclarator (const cp_declarator *declarator, if (decl == NULL_TREE) { + location_t loc = declarator ? declarator->id_loc : input_location; if (staticp) { /* C++ allows static class members. All other work for this is done by grokfield. */ - decl = build_lang_decl_loc (declarator - ? declarator->id_loc - : input_location, - VAR_DECL, unqualified_id, type); + decl = build_lang_decl_loc (loc, VAR_DECL, + unqualified_id, type); set_linkage_for_static_data_member (decl); if (concept_p) error_at (declspecs->locations[ds_concept], @@ -12536,8 +12539,7 @@ grokdeclarator (const cp_declarator *declarator, unqualified_id); constexpr_p = false; } - decl = build_decl (input_location, - FIELD_DECL, unqualified_id, type); + decl = build_decl (loc, FIELD_DECL, unqualified_id, type); DECL_NONADDRESSABLE_P (decl) = bitfield; if (bitfield && !unqualified_id) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1871663415e..9f2b5cf66f8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-12-06 Paolo Carlini + + * g++.dg/parse/bitfield7.C: New. + * g++.dg/other/bitfield2.C: Check location and type. + * g++.dg/parse/bitfield1.C: Likewise. + * g++.dg/parse/bitfield2.C: Likewise. + 2018-12-06 Alexandre Oliva PR c++/86747 diff --git a/gcc/testsuite/g++.dg/other/bitfield2.C b/gcc/testsuite/g++.dg/other/bitfield2.C index cd9a837dcab..f81f868a2fc 100644 --- a/gcc/testsuite/g++.dg/other/bitfield2.C +++ b/gcc/testsuite/g++.dg/other/bitfield2.C @@ -3,7 +3,7 @@ struct A { - double d : 2; // { dg-error "non-integral" } + double d : 2; // { dg-error "10:bit-field .d. with non-integral type .double." } A() {} ~A() {} }; diff --git a/gcc/testsuite/g++.dg/parse/bitfield1.C b/gcc/testsuite/g++.dg/parse/bitfield1.C index 2e076058508..16088936cca 100644 --- a/gcc/testsuite/g++.dg/parse/bitfield1.C +++ b/gcc/testsuite/g++.dg/parse/bitfield1.C @@ -2,7 +2,7 @@ struct A { - double i : 8; // { dg-error "type" } + double i : 8; // { dg-error "10:bit-field .i. with non-integral type .double." } }; void foo(A& a) diff --git a/gcc/testsuite/g++.dg/parse/bitfield2.C b/gcc/testsuite/g++.dg/parse/bitfield2.C index f84cc673e57..e0fb84e788f 100644 --- a/gcc/testsuite/g++.dg/parse/bitfield2.C +++ b/gcc/testsuite/g++.dg/parse/bitfield2.C @@ -4,7 +4,7 @@ struct X {}; struct A { - X x : 2; // { dg-error "non-integral type" } + X x : 2; // { dg-error "7:bit-field .x. with non-integral type .X." } }; struct B : A {}; @@ -19,7 +19,7 @@ C c; template struct D { - T t : 3; // { dg-error "non-integral type" } + T t : 3; // { dg-error "5:bit-field .double D\\::t. with non-integral type .double." } }; D d; // { dg-message "required" } @@ -28,7 +28,7 @@ template struct E { typedef T* U; - U t : 3; // { dg-error "non-integral type" } + U t : 3; // { dg-error "5:bit-field .t. with non-integral type .E\\::U." } }; E e; diff --git a/gcc/testsuite/g++.dg/parse/bitfield7.C b/gcc/testsuite/g++.dg/parse/bitfield7.C new file mode 100644 index 00000000000..ccc7166f1db --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/bitfield7.C @@ -0,0 +1,4 @@ +struct A +{ + friend int : 1; // { dg-error "unnamed field" } +};