parser.c (make_id_declarator): Add location_t parameter.
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 14 Nov 2018 17:50:25 +0000 (17:50 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 14 Nov 2018 17:50:25 +0000 (17:50 +0000)
/cp
2018-11-14  Paolo Carlini  <paolo.carlini@oracle.com>

* parser.c (make_id_declarator): Add location_t parameter.
(cp_parser_lambda_declarator_opt): Adjust call.
(cp_parser_decomposition_declaration): Likewise.
(cp_parser_alias_declaration): Likewise.
(cp_parser_direct_declarator): Likewise.
(cp_parser_member_declaration): Likewise.
(cp_parser_objc_class_ivars): Likewise.
* decl.c (grokdeclarator): Use declarator->id_loc in two error
messages.

/testsuite
2018-11-14  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/cpp0x/nsdmi-union6.C: Test locations too.
* g++.dg/cpp0x/nsdmi6.C: Likewise.
* g++.dg/ext/flexary4.C: Likewise.
* g++.dg/ext/flexary9.C: Likewise.
* g++.dg/other/incomplete2.C: Likewise.
* g++.dg/parse/friend12.C: Likewise.

From-SVN: r266155

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-union6.C
gcc/testsuite/g++.dg/cpp0x/nsdmi6.C
gcc/testsuite/g++.dg/ext/flexary4.C
gcc/testsuite/g++.dg/ext/flexary9.C
gcc/testsuite/g++.dg/other/incomplete2.C
gcc/testsuite/g++.dg/parse/friend12.C

index ee5c2ce844622a2a432b28d5da14c383780179f5..7e6ba17669df3c355f87082af22dc9f8e23abb02 100644 (file)
@@ -1,3 +1,15 @@
+2018-11-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * parser.c (make_id_declarator): Add location_t parameter.
+       (cp_parser_lambda_declarator_opt): Adjust call.
+       (cp_parser_decomposition_declaration): Likewise.
+       (cp_parser_alias_declaration): Likewise.
+       (cp_parser_direct_declarator): Likewise.
+       (cp_parser_member_declaration): Likewise.
+       (cp_parser_objc_class_ivars): Likewise.
+       * decl.c (grokdeclarator): Use declarator->id_loc in two error
+       messages.
+
 2018-11-14  Jakub Jelinek  <jakub@redhat.com>
 
        P1236R1 - Signed integers are two's complement
index 89a1823162630157449a25b1dfe5213c1a8df93c..7d63bbe7f1bb8b43122742bb392c0f1bda9f2e63 100644 (file)
@@ -12408,8 +12408,9 @@ grokdeclarator (const cp_declarator *declarator,
              {
                if (unqualified_id)
                  {
-                   error ("field %qD has incomplete type %qT",
-                          unqualified_id, type);
+                   error_at (declarator->id_loc,
+                             "field %qD has incomplete type %qT",
+                             unqualified_id, type);
                    cxx_incomplete_type_inform (strip_array_types (type));
                  }
                else
@@ -12423,8 +12424,9 @@ grokdeclarator (const cp_declarator *declarator,
          {
            if (friendp)
              {
-               error ("%qE is neither function nor member function; "
-                      "cannot be declared friend", unqualified_id);
+               error_at (declarator->id_loc,
+                         "%qE is neither function nor member function; "
+                         "cannot be declared friend", unqualified_id);
                return error_mark_node;
              }
            decl = NULL_TREE;
index e9e49b15702bcfa9bcdfa39506ba4391c658fb0f..8833e3db746aab408acde2c8d7b258a65f6d0311 100644 (file)
@@ -1453,7 +1453,7 @@ make_declarator (cp_declarator_kind kind)
 
 static cp_declarator *
 make_id_declarator (tree qualifying_scope, tree unqualified_name,
-                   special_function_kind sfk)
+                   special_function_kind sfk, location_t id_location)
 {
   cp_declarator *declarator;
 
@@ -1478,7 +1478,8 @@ make_id_declarator (tree qualifying_scope, tree unqualified_name,
   declarator->u.id.qualifying_scope = qualifying_scope;
   declarator->u.id.unqualified_name = unqualified_name;
   declarator->u.id.sfk = sfk;
-  
+  declarator->id_loc = id_location;
+
   return declarator;
 }
 
@@ -10686,7 +10687,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
     p = obstack_alloc (&declarator_obstack, 0);
 
-    declarator = make_id_declarator (NULL_TREE, call_op_identifier, sfk_none);
+    declarator = make_id_declarator (NULL_TREE, call_op_identifier, sfk_none,
+                                    LAMBDA_EXPR_LOCATION (lambda_expr));
 
     quals = (LAMBDA_EXPR_MUTABLE_P (lambda_expr)
             ? TYPE_UNQUALIFIED : TYPE_QUAL_CONST);
@@ -10697,7 +10699,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
                                       exception_spec,
                                        return_type,
                                        /*requires_clause*/NULL_TREE);
-    declarator->id_loc = LAMBDA_EXPR_LOCATION (lambda_expr);
     declarator->std_attributes = attributes;
 
     fco = grokmethod (&return_type_specs,
@@ -13473,10 +13474,13 @@ cp_parser_decomposition_declaration (cp_parser *parser,
   FOR_EACH_VEC_ELT (v, i, e)
     {
       if (i == 0)
-       declarator = make_id_declarator (NULL_TREE, e.get_value (), sfk_none);
+       declarator = make_id_declarator (NULL_TREE, e.get_value (),
+                                        sfk_none, e.get_location ());
       else
-       declarator->u.id.unqualified_name = e.get_value ();
-      declarator->id_loc = e.get_location ();
+       {
+         declarator->u.id.unqualified_name = e.get_value ();
+         declarator->id_loc = e.get_location ();
+       }
       tree elt_pushed_scope;
       tree decl2 = start_decl (declarator, &decl_specs, SD_INITIALIZED,
                               NULL_TREE, NULL_TREE, &elt_pushed_scope);
@@ -19294,8 +19298,7 @@ cp_parser_alias_declaration (cp_parser* parser)
                                               /*declarator=*/NULL))
     return error_mark_node;
 
-  declarator = make_id_declarator (NULL_TREE, id, sfk_none);
-  declarator->id_loc = id_location;
+  declarator = make_id_declarator (NULL_TREE, id, sfk_none, id_location);
 
   member_p = at_class_scope_p ();
   if (member_p)
@@ -20699,9 +20702,8 @@ cp_parser_direct_declarator (cp_parser* parser,
              }
            declarator = make_id_declarator (qualifying_scope,
                                             unqualified_name,
-                                            sfk);
+                                            sfk, token->location);
            declarator->std_attributes = attrs;
-           declarator->id_loc = token->location;
            declarator->parameter_pack_p = pack_expansion_p;
 
            if (pack_expansion_p)
@@ -23993,6 +23995,8 @@ cp_parser_member_declaration (cp_parser* parser)
              tree identifier;
              tree width;
              tree late_attributes = NULL_TREE;
+             location_t id_location
+               = cp_lexer_peek_token (parser->lexer)->location;
 
              if (named_bitfld)
                identifier = cp_parser_identifier (parser);
@@ -24061,7 +24065,8 @@ cp_parser_member_declaration (cp_parser* parser)
              decl = grokbitfield (identifier
                                   ? make_id_declarator (NULL_TREE,
                                                         identifier,
-                                                        sfk_none)
+                                                        sfk_none,
+                                                        id_location)
                                   : NULL,
                                   &decl_specifiers,
                                   width, initializer,
@@ -30608,7 +30613,7 @@ cp_parser_objc_class_ivars (cp_parser* parser)
              /* Get the name of the bitfield.  */
              declarator = make_id_declarator (NULL_TREE,
                                               cp_parser_identifier (parser),
-                                              sfk_none);
+                                              sfk_none, token->location);
 
             eat_colon:
              cp_lexer_consume_token (parser->lexer);  /* Eat ':'.  */
index a94cb786840c0e0eca821a37602ae050c8a6dace..524db2686170cc83fbf9f74c98a1a6530b7b9b43 100644 (file)
@@ -1,3 +1,12 @@
+2018-11-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/cpp0x/nsdmi-union6.C: Test locations too.
+       * g++.dg/cpp0x/nsdmi6.C: Likewise.
+       * g++.dg/ext/flexary4.C: Likewise.
+       * g++.dg/ext/flexary9.C: Likewise.
+       * g++.dg/other/incomplete2.C: Likewise.
+       * g++.dg/parse/friend12.C: Likewise.
+
 2018-11-14  Jakub Jelinek  <jakub@redhat.com>
 
        P1236R1 - Signed integers are two's complement
index 764fe21d610596d887a47e2775747bc73afad103..beb6c3864ec88bdf9f7ec95beced0a1c572940b4 100644 (file)
@@ -5,7 +5,7 @@ struct F;          // { dg-message "forward declaration" }
 
 union U            // { dg-message "not complete" }
 {
-  U u[1] = { 0 };  // { dg-error "incomplete type" }
+  U u[1] = { 0 };  // { dg-error "5:field .u. has incomplete type" }
 };
 
 template<typename T>
@@ -18,20 +18,20 @@ template union UT<int>;
 
 union UF
 {
-  F u[1] = { 0 };  // { dg-error "incomplete type" }
+  F u[1] = { 0 };  // { dg-error "5:field .u. has incomplete type" }
 };
 
 template<typename T>
 union UFT
 {
-  F u[1] = { 0 };  // { dg-error "incomplete type" }
+  F u[1] = { 0 };  // { dg-error "5:field .u. has incomplete type" }
 };
 
 template union UFT<int>;
 
 struct S           // { dg-message "not complete" }
 {
-  S s[1] = { 0 };  // { dg-error "incomplete type" }
+  S s[1] = { 0 };  // { dg-error "5:field .s. has incomplete type" }
 };
 
 template<typename T>
@@ -44,13 +44,13 @@ template class ST<int>;
 
 struct SF
 {
-  F s[1] = { 0 };  // { dg-error "incomplete type" }
+  F s[1] = { 0 };  // { dg-error "5:field .s. has incomplete type" }
 };
 
 template<typename T>
 struct SFT
 {
-  F s[1] = { 0 };  // { dg-error "incomplete type" }
+  F s[1] = { 0 };  // { dg-error "5:field .s. has incomplete type" }
 };
 
 template class SFT<int>;
index f88a347426ad87347530058c12cd6686908e8191..1988319cf3769b930bea041836394608b776af66 100644 (file)
@@ -4,5 +4,6 @@
 struct A
 {
     typedef int int T; // { dg-error "two or more data types in declaration" }
-    struct T x[1] = { 0 }; // { dg-error "incomplete type|forward" }
+    struct T x[1] = { 0 }; // { dg-error "14:field .x. has incomplete type" }
+// { dg-message "forward declaration" "" { target c++11 } .-1 }  
 };
index 29d6bddf3365364d41b2cd4f38f28cc69dbbfe38..bd28cf55de2bedf4e8c1cd559414ebaafc0b5c8f 100644 (file)
@@ -143,7 +143,7 @@ struct Sx23 {
 
 struct Sx24 {
   struct S;
-  S a_x [];                 // { dg-error "incomplete type" }
+  S a_x [];                 // { dg-error "5:field .a_x. has incomplete type" }
 };
 
 struct Sx25 {
index 07eb966ae47aa72b16d548401470d35638449f93..5ebcdf507575f6341a138d5a59606c9373b0ad67 100644 (file)
@@ -136,7 +136,8 @@ struct Sx23 {
 // array warning.
 struct Sx24 {
   struct S;
-  S a_x [0];                // { dg-message "incomplete type|zero-size array" }
+  S a_x [0];                // { dg-error "5:field .a_x. has incomplete type" }
+// { dg-warning "zero-size array" "" { target *-*-* } .-1 }
 };
 
 struct Sx25 {
index 127bf588e93e3159e37589aaee41fd4555ba9a90..8ea583e52fd68160ae3d89e21068b717341f0603 100644 (file)
@@ -5,7 +5,7 @@ struct A;
 
 struct B
 {
-  A a : 1;  // { dg-error "incomplete" }
+  A a : 1;  // { dg-error "5:field .a. has incomplete type .A" }
 };
 
 struct S
index d4e0ceea9ac2613a83c71fa7c19478e34da9bbde..606122e9840ca5d972d7cfd65277e8ebb0b61d7b 100644 (file)
@@ -2,5 +2,5 @@
 
 struct A
 {
-  friend int i = 0;  // { dg-error "cannot be declared friend" }
+  friend int i = 0;  // { dg-error "14:.i. is neither function nor member function; cannot be declared friend" }
 };