typeck2.c (build_functional_cast): Add location_t parameter and use it.
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 5 Dec 2019 08:59:24 +0000 (08:59 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 5 Dec 2019 08:59:24 +0000 (08:59 +0000)
/gcc/cp
2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>

* typeck2.c (build_functional_cast): Add location_t parameter
and use it.
* cp-tree.h: Update declaration.
* parser.c (cp_parser_functional_cast): Adjust call.
* call.c (build_op_delete_call): Likewise.
(build_new_method_call_1): Likewise.
* decl.c (check_initializer): Likewise.
* pt.c (tsubst_copy_and_build): Likewise.
* semantics.c (finish_compound_literal): Likewise.

/libcc1
2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>

* libcp1plugin.cc (plugin_build_expression_list_expr): Adjust
build_functional_cast call.

/testsuite
2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>

* g++.dg/diagnostic/functional-cast-to-array-type-1.C: New.
* g++.dg/cpp0x/auto25.C: Check location(s) too.
* g++.dg/cpp0x/auto28.C: Likewise.
* g++.dg/init/reference2.C: Likewise.
* g++.dg/parse/template2.C: Likewise.
* g++.dg/template/error8.C: Likewise.
* g++.old-deja/g++.ns/crash3.C: Likewise.
* g++.old-deja/g++.ns/template7.C: Likewise.
* g++.old-deja/g++.pt/crash8.C: Likewise.

From-SVN: r278987

20 files changed:
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto25.C
gcc/testsuite/g++.dg/cpp0x/auto28.C
gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/reference2.C
gcc/testsuite/g++.dg/parse/template2.C
gcc/testsuite/g++.dg/template/error8.C
gcc/testsuite/g++.old-deja/g++.ns/crash3.C
gcc/testsuite/g++.old-deja/g++.ns/template7.C
gcc/testsuite/g++.old-deja/g++.pt/crash8.C
libcc1/ChangeLog
libcc1/libcp1plugin.cc

index bde12e50ad91962ab067ff78992cabf0fbd01b04..6cda4e72d52f4328f59f297d5c00785d7676b11d 100644 (file)
@@ -1,3 +1,15 @@
+2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * typeck2.c (build_functional_cast): Add location_t parameter
+       and use it.
+       * cp-tree.h: Update declaration.
+       * parser.c (cp_parser_functional_cast): Adjust call.
+       * call.c (build_op_delete_call): Likewise.
+       (build_new_method_call_1): Likewise.
+       * decl.c (check_initializer): Likewise.
+       * pt.c (tsubst_copy_and_build): Likewise.
+       * semantics.c (finish_compound_literal): Likewise.
+
 2019-12-04  David Edelsohn  <dje.gcc@gmail.com>
 
        * cp-gimplify.c: Include tm_p.h.
index 5e9523e97b566d3be270ffa6a12d43bcd739fbf5..92d3d688f0cf5e4b31030ad7927fd8ba719485b7 100644 (file)
@@ -6933,7 +6933,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
              rtype = cv_unqualified (rtype);
              rtype = TYPE_POINTER_TO (rtype);
              addr = cp_convert (rtype, oaddr, complain);
-             destroying = build_functional_cast (destroying, NULL_TREE,
+             destroying = build_functional_cast (input_location,
+                                                 destroying, NULL_TREE,
                                                  complain);
            }
 
@@ -9997,7 +9998,8 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
                     basetype, name))
        inform (input_location, "for a function-style cast, remove the "
                "redundant %<::%D%>", name);
-      call = build_functional_cast (basetype, build_tree_list_vec (user_args),
+      call = build_functional_cast (input_location, basetype,
+                                   build_tree_list_vec (user_args),
                                    complain);
       return call;
     }
index 89828d904d5a13882fbf2afba0fdb1a60d296a93..a392be6b24fca88f6b9ed4685ff5bbf09ebeabc3 100644 (file)
@@ -7681,7 +7681,8 @@ extern tree build_scoped_ref                      (tree, tree, tree *);
 extern tree build_x_arrow                      (location_t, tree,
                                                 tsubst_flags_t);
 extern tree build_m_component_ref              (tree, tree, tsubst_flags_t);
-extern tree build_functional_cast              (tree, tree, tsubst_flags_t);
+extern tree build_functional_cast              (location_t, tree, tree,
+                                                tsubst_flags_t);
 extern tree add_exception_specifier            (tree, tree, tsubst_flags_t);
 extern tree merge_exception_specifiers         (tree, tree);
 
index 481c798a2cfa02068b3e3e5ada692a0255a3f261..7897327ad9a9a49d512e9a8500b854d25911a1b1 100644 (file)
@@ -6764,7 +6764,8 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
              if (CLASS_TYPE_P (type)
                  && (!init || TREE_CODE (init) == TREE_LIST))
                {
-                 init = build_functional_cast (type, init, tf_none);
+                 init = build_functional_cast (input_location, type,
+                                               init, tf_none);
                  if (TREE_CODE (init) == TARGET_EXPR)
                    TARGET_EXPR_DIRECT_INIT_P (init) = true;
                }
index 10ff01666b9f11219093bf8ea02683a22553b39c..05be440cb9b8e0b968c345e8110991ddb3149840 100644 (file)
@@ -29268,8 +29268,17 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
       release_tree_vector (vec);
     }
 
-  cast = build_functional_cast (type, expression_list,
+  /* Create a location of the form:
+       float(i)
+       ^~~~~~~~
+     with caret == start at the start of the type name,
+     finishing at the closing paren.  */
+  location_t combined_loc = make_location (start_loc, start_loc,
+                                          parser->lexer);
+  cast = build_functional_cast (combined_loc, type, expression_list,
                                 tf_warning_or_error);
+  cast.set_location (combined_loc);
+  
   /* [expr.const]/1: In an integral constant expression "only type
      conversions to integral or enumeration type can be used".  */
   if (TREE_CODE (type) == TYPE_DECL)
@@ -29280,13 +29289,6 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
                                                     NIC_CONSTRUCTOR))
     return error_mark_node;
 
-  /* Create a location of the form:
-       float(i)
-       ^~~~~~~~
-     with caret == start at the start of the type name,
-     finishing at the closing paren.  */
-  location_t combined_loc = make_location (start_loc, start_loc, parser->lexer);
-  cast.set_location (combined_loc);
   return cast;
 }
 
index 5088dc125ce61adcfc2e3b0f9033bee8cefcb59b..0990297892e54d21a59080e1adf9f17add361c80 100644 (file)
@@ -19017,7 +19017,7 @@ tsubst_copy_and_build (tree t,
        switch (TREE_CODE (t))
          {
          case CAST_EXPR:
-           r = build_functional_cast (type, op, complain);
+           r = build_functional_cast (input_location, type, op, complain);
            break;
          case REINTERPRET_CAST_EXPR:
            r = build_reinterpret_cast (type, op, complain);
index 17de39eea5489af212e46fb30dfe047e19dd0498..83a7891e57beedaf8cf98ae1e50ab2dec6ed7d65 100644 (file)
@@ -2929,7 +2929,8 @@ finish_compound_literal (tree type, tree compound_literal,
         that it came from T{} rather than T({}).  */
       CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
       compound_literal = build_tree_list (NULL_TREE, compound_literal);
-      return build_functional_cast (type, compound_literal, complain);
+      return build_functional_cast (input_location, type,
+                                   compound_literal, complain);
     }
 
   if (TREE_CODE (type) == ARRAY_TYPE
index 7fda6266a35037f3d6dded9eb1cde7cfd24453bd..ca321f3e35e7e785abec176db8a47cb55c8114b5 100644 (file)
@@ -2228,7 +2228,8 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain)
 /* Return a tree node for the expression TYPENAME '(' PARMS ')'.  */
 
 tree
-build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
+build_functional_cast (location_t loc, tree exp, tree parms,
+                      tsubst_flags_t complain)
 {
   /* This is either a call to a constructor,
      or a C cast in C++'s `functional' notation.  */
@@ -2254,7 +2255,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
   if (TREE_CODE (type) == ARRAY_TYPE)
     {
       if (complain & tf_error)
-       error ("functional cast to array type %qT", type);
+       error_at (loc, "functional cast to array type %qT", type);
       return error_mark_node;
     }
 
@@ -2263,7 +2264,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
       if (!CLASS_PLACEHOLDER_TEMPLATE (anode))
        {
          if (complain & tf_error)
-           error ("invalid use of %qT", anode);
+           error_at (loc, "invalid use of %qT", anode);
          return error_mark_node;
        }
       else if (!parms)
@@ -2276,8 +2277,8 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
          if (type == error_mark_node)
            {
              if (complain & tf_error)
-               error ("cannot deduce template arguments for %qT from %<()%>",
-                      anode);
+               error_at (loc, "cannot deduce template arguments "
+                         "for %qT from %<()%>", anode);
              return error_mark_node;
            }
        }
@@ -2296,7 +2297,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
       if (TYPE_REF_P (type) && !parms)
        {
          if (complain & tf_error)
-           error ("invalid value-initialization of reference type");
+           error_at (loc, "invalid value-initialization of reference type");
          return error_mark_node;
        }
 
index 03a97b5f53c6e18f5f940cc590670cfc9fb230d2..75050022f0ed3a4fb50c52a6d82f2acc146efbfd 100644 (file)
@@ -1,3 +1,15 @@
+2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * g++.dg/diagnostic/functional-cast-to-array-type-1.C: New.
+       * g++.dg/cpp0x/auto25.C: Check location(s) too.
+       * g++.dg/cpp0x/auto28.C: Likewise.
+       * g++.dg/init/reference2.C: Likewise.
+       * g++.dg/parse/template2.C: Likewise.
+       * g++.dg/template/error8.C: Likewise.
+       * g++.old-deja/g++.ns/crash3.C: Likewise.
+       * g++.old-deja/g++.ns/template7.C: Likewise.
+       * g++.old-deja/g++.pt/crash8.C: Likewise.
+
 2019-12-03  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/91582
index 9e08a5bf38186ad888432a9b41aca07092195c9d..19d51bc8590feefec1d717b92e011534e33c15e9 100644 (file)
@@ -3,10 +3,10 @@
 
 template<int> struct A
 {
-  int a[auto(1)]; // { dg-error "invalid use of" }
+  int a[auto(1)]; // { dg-error "9:invalid use of" }
 };
 
 template<int> void foo()
 {
-  int a[auto(1)]; // { dg-error "invalid use of" }
+  int a[auto(1)]; // { dg-error "9:invalid use of" }
 }
index 441d8843a6ecd63679f50391a8aacf5ba4511ecc..1ffd9b76255a1641e376bb04f2f42d4d1c45f8b8 100644 (file)
@@ -1,4 +1,4 @@
 // PR c++/51404
 // { dg-do compile { target c++11 } }
 
-int i = auto().x;  // { dg-error "invalid use of" }
+int i = auto().x;  // { dg-error "9:invalid use of" }
diff --git a/gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C b/gcc/testsuite/g++.dg/diagnostic/functional-cast-to-array-type-1.C
new file mode 100644 (file)
index 0000000..e9bdb64
--- /dev/null
@@ -0,0 +1,2 @@
+typedef int A [1];
+A a = A(1);  // { dg-error "7:functional cast to array type" }
index 903c06496d5cdbe69a9a6ba886b62c313247953a..08d3d97c998ab9639a729c890bbd06a6a053b560 100644 (file)
@@ -8,6 +8,6 @@ template <int a1>
 void f()
 {
   typedef int& T;
-  T a = T();  // { dg-error "value-initialization of reference" }
+  T a = T();  // { dg-error "9:invalid value-initialization of reference" }
 }
 
index 93c7defb165b19b7cab766b9d7ac13593b53f50a..3cb27a85c007df09b97363e7b721f781862df664 100644 (file)
@@ -3,5 +3,6 @@ namespace N {
 }
 
 int main() {
-  N::C(); // { dg-error "template|deduction" }
+  N::C(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } }
+  // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 }
 }
index 30872a2e953da2dc147deab04155ea46bb7b212c..6cae360aa161ac65c9c3a81ecde6d39d6d7d8ac2 100644 (file)
@@ -3,5 +3,6 @@
 template <typename T> struct S {};
 
 void f() {
-  throw S (); // { dg-error "template" }
+  throw S (); // { dg-error "9:cannot deduce template arguments" "" { target c++17 } }
+  // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 }
 }
index 37211d0db3fe24395197876a9b637be6671fc2c7..189298de6c58f4a71dd92f3a229df30be429a875 100644 (file)
@@ -6,5 +6,6 @@ namespace N {
 
 void f()
 {
-  N::S(); // { dg-error "" } invalid use of template
+  N::S(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } } invalid use of template
+  // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 }
 }
index 876096b7490ea47a9f67a7f4539179ec1bf934e1..71366b79d02c2c674206c82f8555fb0c8fd593d8 100644 (file)
@@ -8,5 +8,6 @@ namespace foo {
 }
 
 void baz() {
-  foo::bar(); // { dg-error "" } template used as expression
+  foo::bar(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 }
 }
index de2dd9dc7de040ab55fe5edcf10fc118e3640a85..7b4eff595bfc24ce378769a8c0b0d8a67a147fe2 100644 (file)
@@ -21,10 +21,12 @@ void doit(T x) {
   q2 = TestClass2<T>();
 
   TestClass1<T> p1;
-  p1 = TestClass1(); // { dg-error "" } template used as expression
+  p1 = TestClass1(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 }
 
   TestClass2<T> p2;
-  p2 = TestClass2(); // { dg-error "" } template used as expression
+  p2 = TestClass2(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 }
 }
 
 int main() {
index 92b5cb735e8d48db3680166c1ce71db9e7d0fc31..169a0a9eeeb4fcd6915a9099ca2dbbc6abbe0c84 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * libcp1plugin.cc (plugin_build_expression_list_expr): Adjust
+       build_functional_cast call.
+
 2019-11-25  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * libcp1plugin.cc (plugin_pragma_push_user_expression): Update
index 232ab976ab585f8a6f02a5a31e61b627b2555eaf..c728310618f3aa67e4981eb50810db214479c58e 100644 (file)
@@ -3155,7 +3155,7 @@ plugin_build_expression_list_expr (cc1_plugin::connection *self,
     case CHARS2 ('c', 'v'): // conversion with parenthesized expression list
       gcc_assert (TYPE_P (type));
       args = args_to_tree_list (values_in);
-      result = build_functional_cast (type, args, tf_error);
+      result = build_functional_cast (input_location, type, args, tf_error);
       break;
 
     case CHARS2 ('t', 'l'): // conversion with braced expression list