class.c (check_bitfield_decl): In error message about non-integral type print the...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 6 Dec 2018 23:20:16 +0000 (23:20 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 6 Dec 2018 23:20:16 +0000 (23:20 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/bitfield2.C
gcc/testsuite/g++.dg/parse/bitfield1.C
gcc/testsuite/g++.dg/parse/bitfield2.C
gcc/testsuite/g++.dg/parse/bitfield7.C [new file with mode: 0644]

index e092c4490f55f0254efe17df41ff7baedf591dfd..707058064e09b728b8ad7c65ae5862dcee836d54 100644 (file)
@@ -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
index 9c175f85cf655c43f97b64022ed2bc4fb05c909e..1bcb146fbb64129661f0c8ca75a940f355e8bc74 100644 (file)
@@ -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
index e662f63bb0f07ffafecb8c9a3f7eb6c81e163755..832e73a64dc75d5c99cab32b68b8c7362ebaa41e 100644 (file)
@@ -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)
                  {
index 1871663415ed9d8093c0be2424bbfff7a13081ce..9f2b5cf66f849f55089219ade5971b41d7ef7711 100644 (file)
@@ -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
index cd9a837dcab04e046ec39bfd0b92ce5daf3d9405..f81f868a2fc28abc392c28af66f6dc6446fb3ce1 100644 (file)
@@ -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() {}
 };
index 2e076058508fbdbfe724d7addacb9eb36aaec516..16088936cca5a3433750e015a89046b0913463c8 100644 (file)
@@ -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)
index f84cc673e57475e66fcafe77040c47c251f0512b..e0fb84e788fb3eb38dbc0f6191778208bfea528f 100644 (file)
@@ -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 (file)
index 0000000..ccc7166
--- /dev/null
@@ -0,0 +1,4 @@
+struct A
+{
+  friend int : 1;  // { dg-error "unnamed field" }
+};