diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2018-12-06 23:20:16 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2018-12-06 23:20:16 +0000 |
commit | 3c1eaf67e9a4a1a63ff26b24c4b1f9f1a7c58bc4 (patch) | |
tree | 3bd4768e1ce9c05ec207274fe1aa85aee839810a /gcc | |
parent | d7711adcd5226995063342631e1ce5c2ff055981 (diff) | |
download | gcc-3c1eaf67e9a4a1a63ff26b24c4b1f9f1a7c58bc4.zip gcc-3c1eaf67e9a4a1a63ff26b24c4b1f9f1a7c58bc4.tar.gz gcc-3c1eaf67e9a4a1a63ff26b24c4b1f9f1a7c58bc4.tar.bz2 |
class.c (check_bitfield_decl): In error message about non-integral type print the type itself too.
/cp
2018-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* 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 <paolo.carlini@oracle.com>
* 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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/class.c | 3 | ||||
-rw-r--r-- | gcc/cp/decl.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/bitfield2.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/bitfield1.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/bitfield2.C | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/bitfield7.C | 4 |
8 files changed, 37 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e092c44..7070580 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-12-06 Paolo Carlini <paolo.carlini@oracle.com> + + * 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 <aoliva@redhat.com> PR c++/86747 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 9c175f8..1bcb146 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 e662f63..832e73a 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 1871663..9f2b5cf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-12-06 Paolo Carlini <paolo.carlini@oracle.com> + + * 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 <aoliva@redhat.com> PR c++/86747 diff --git a/gcc/testsuite/g++.dg/other/bitfield2.C b/gcc/testsuite/g++.dg/other/bitfield2.C index cd9a837..f81f868 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 2e07605..1608893 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 f84cc67..e0fb84e 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<int> c; template <typename T> struct D { - T t : 3; // { dg-error "non-integral type" } + T t : 3; // { dg-error "5:bit-field .double D\\<double\\>::t. with non-integral type .double." } }; D<double> d; // { dg-message "required" } @@ -28,7 +28,7 @@ template <typename T> 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\\<T\\>::U." } }; E<double> e; diff --git a/gcc/testsuite/g++.dg/parse/bitfield7.C b/gcc/testsuite/g++.dg/parse/bitfield7.C new file mode 100644 index 0000000..ccc7166 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/bitfield7.C @@ -0,0 +1,4 @@ +struct A +{ + friend int : 1; // { dg-error "unnamed field" } +}; |