Commit 3c1eaf67 by Paolo Carlini Committed by Paolo Carlini

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
parent d7711adc
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> 2018-12-06 Alexandre Oliva <aoliva@redhat.com>
PR c++/86747 PR c++/86747
......
...@@ -3218,7 +3218,8 @@ check_bitfield_decl (tree field) ...@@ -3218,7 +3218,8 @@ check_bitfield_decl (tree field)
/* Detect invalid bit-field type. */ /* Detect invalid bit-field type. */
if (!INTEGRAL_OR_ENUMERATION_TYPE_P (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; w = error_mark_node;
} }
else else
......
...@@ -12446,9 +12446,13 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -12446,9 +12446,13 @@ grokdeclarator (const cp_declarator *declarator,
{ {
if (friendp) if (friendp)
{ {
error_at (declarator->id_loc, if (unqualified_id && declarator)
"%qE is neither function nor member function; " error_at (declarator->id_loc,
"cannot be declared friend", unqualified_id); "%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; return error_mark_node;
} }
decl = NULL_TREE; decl = NULL_TREE;
...@@ -12483,14 +12487,13 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -12483,14 +12487,13 @@ grokdeclarator (const cp_declarator *declarator,
if (decl == NULL_TREE) if (decl == NULL_TREE)
{ {
location_t loc = declarator ? declarator->id_loc : input_location;
if (staticp) if (staticp)
{ {
/* C++ allows static class members. All other work /* C++ allows static class members. All other work
for this is done by grokfield. */ for this is done by grokfield. */
decl = build_lang_decl_loc (declarator decl = build_lang_decl_loc (loc, VAR_DECL,
? declarator->id_loc unqualified_id, type);
: input_location,
VAR_DECL, unqualified_id, type);
set_linkage_for_static_data_member (decl); set_linkage_for_static_data_member (decl);
if (concept_p) if (concept_p)
error_at (declspecs->locations[ds_concept], error_at (declspecs->locations[ds_concept],
...@@ -12536,8 +12539,7 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -12536,8 +12539,7 @@ grokdeclarator (const cp_declarator *declarator,
unqualified_id); unqualified_id);
constexpr_p = false; constexpr_p = false;
} }
decl = build_decl (input_location, decl = build_decl (loc, FIELD_DECL, unqualified_id, type);
FIELD_DECL, unqualified_id, type);
DECL_NONADDRESSABLE_P (decl) = bitfield; DECL_NONADDRESSABLE_P (decl) = bitfield;
if (bitfield && !unqualified_id) if (bitfield && !unqualified_id)
{ {
......
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> 2018-12-06 Alexandre Oliva <aoliva@redhat.com>
PR c++/86747 PR c++/86747
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
struct A 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() {}
~A() {} ~A() {}
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
struct A 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) void foo(A& a)
......
...@@ -4,7 +4,7 @@ struct X {}; ...@@ -4,7 +4,7 @@ struct X {};
struct A 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 {}; struct B : A {};
...@@ -19,7 +19,7 @@ C<int> c; ...@@ -19,7 +19,7 @@ C<int> c;
template <typename T> template <typename T>
struct D 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" } D<double> d; // { dg-message "required" }
...@@ -28,7 +28,7 @@ template <typename T> ...@@ -28,7 +28,7 @@ template <typename T>
struct E struct E
{ {
typedef T* U; 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; E<double> e;
struct A
{
friend int : 1; // { dg-error "unnamed field" }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment