c++: Fix thinko in auto return type checking [PR98441]
[gcc.git] / libcc1 / libcp1plugin.cc
index f8ed90b835f5ef6bef72e6e9b9c8acf93a21a2ce..27a6175e34e6a234651d53a70b1f3b2bbf79275f 100644 (file)
@@ -1,5 +1,5 @@
 /* Library interface to C++ front end.
-   Copyright (C) 2014-2018 Free Software Foundation, Inc.
+   Copyright (C) 2014-2021 Free Software Foundation, Inc.
 
    This file is part of GCC.  As it interacts with GDB through libcc1,
    they all become a single program as regards the GNU GPL's requirements.
@@ -353,8 +353,7 @@ supplement_binding (cxx_binding *binding, tree decl)
           /* If TARGET_BVAL is anticipated but has not yet been
              declared, pretend it is not there at all.  */
           || (TREE_CODE (target_bval) == FUNCTION_DECL
-              && DECL_ANTICIPATED (target_bval)
-              && !DECL_HIDDEN_FRIEND_P (target_bval)))
+              && DECL_IS_UNDECLARED_BUILTIN (target_bval)))
     binding->value = decl;
   else if (TREE_CODE (target_bval) == TYPE_DECL
           && DECL_ARTIFICIAL (target_bval)
@@ -407,7 +406,7 @@ supplement_binding (cxx_binding *binding, tree decl)
           && DECL_EXTERNAL (target_decl) && DECL_EXTERNAL (target_bval)
           && !DECL_CLASS_SCOPE_P (target_decl))
     {
-      duplicate_decls (decl, binding->value, /*newdecl_is_friend=*/false);
+      duplicate_decls (decl, binding->value);
       ok = false;
     }
   else if (TREE_CODE (decl) == NAMESPACE_DECL
@@ -630,7 +629,8 @@ plugin_pragma_push_user_expression (cpp_reader *)
         usable.  */
       tree this_val = lookup_name (get_identifier ("this"));
       current_class_ref = !this_val ? NULL_TREE
-       : cp_build_indirect_ref (this_val, RO_NULL, tf_warning_or_error);
+       : cp_build_indirect_ref (input_location, this_val, RO_NULL,
+                                tf_warning_or_error);
       current_class_ptr = this_val;
     }
 }
@@ -784,14 +784,14 @@ safe_push_template_decl (tree decl)
 }
 
 static inline tree
-safe_pushtag (tree name, tree type, tag_scope scope)
+safe_pushtag (tree name, tree type)
 {
   void (*save_oracle) (enum cp_oracle_request, tree identifier);
 
   save_oracle = cp_binding_oracle;
   cp_binding_oracle = NULL;
 
-  tree ret = pushtag (name, type, scope);
+  tree ret = pushtag (name, type);
 
   cp_binding_oracle = save_oracle;
 
@@ -799,14 +799,14 @@ safe_pushtag (tree name, tree type, tag_scope scope)
 }
 
 static inline tree
-safe_pushdecl_maybe_friend (tree decl, bool is_friend)
+safe_pushdecl (tree decl)
 {
   void (*save_oracle) (enum cp_oracle_request, tree identifier);
 
   save_oracle = cp_binding_oracle;
   cp_binding_oracle = NULL;
 
-  tree ret = pushdecl (decl, is_friend);
+  tree ret = pushdecl (decl);
 
   cp_binding_oracle = save_oracle;
 
@@ -941,7 +941,7 @@ plugin_add_using_namespace (cc1_plugin::connection *,
 
   gcc_assert (TREE_CODE (used_ns) == NAMESPACE_DECL);
 
-  finish_namespace_using_directive (used_ns, NULL_TREE);
+  finish_using_directive (used_ns, NULL_TREE);
 
   return 1;
 }
@@ -1019,7 +1019,7 @@ plugin_add_using_decl (cc1_plugin::connection *,
     {
       /* We can't be at local scope.  */
       gcc_assert (at_namespace_scope_p ());
-      finish_namespace_using_decl (target, tcontext, identifier);
+      finish_nonmember_using_decl (tcontext, identifier);
     }
 
   return 1;
@@ -1513,7 +1513,7 @@ plugin_build_decl (cc1_plugin::connection *self,
   if (template_decl_p)
     {
       if (RECORD_OR_UNION_CODE_P (code))
-       safe_pushtag (identifier, TREE_TYPE (decl), ts_current);
+       safe_pushtag (identifier, TREE_TYPE (decl));
       else
        decl = safe_push_template_decl (decl);
 
@@ -1532,11 +1532,11 @@ plugin_build_decl (cc1_plugin::connection *self,
        finish_member_declaration (tdecl);
     }
   else if (RECORD_OR_UNION_CODE_P (code))
-    safe_pushtag (identifier, TREE_TYPE (decl), ts_current);
+    safe_pushtag (identifier, TREE_TYPE (decl));
   else if (class_member_p)
     finish_member_declaration (decl);
   else
-    decl = safe_pushdecl_maybe_friend (decl, false);
+    decl = safe_pushdecl (decl);
 
   if ((ctor || dtor)
       /* Don't crash after a duplicate declaration of a cdtor.  */
@@ -1551,7 +1551,7 @@ plugin_build_decl (cc1_plugin::connection *self,
         reversal.  */
       tree save = DECL_CHAIN (decl);
       DECL_CHAIN (decl) = NULL_TREE;
-      clone_function_decl (decl, /*update_methods=*/true);
+      clone_cdtor (decl, /*update_methods=*/true);
       gcc_assert (TYPE_FIELDS (current_class_type) == decl);
       TYPE_FIELDS (current_class_type)
        = nreverse (TYPE_FIELDS (current_class_type));
@@ -1649,7 +1649,7 @@ plugin_add_friend (cc1_plugin::connection * /* self */,
     make_friend_class (type, TREE_TYPE (decl), true);
   else
     {
-      DECL_FRIEND_P (decl) = true;
+      DECL_UNIQUE_FRIEND_P (decl) = true;
       add_friend (type, decl, true);
     }
 
@@ -2651,10 +2651,10 @@ plugin_build_dependent_expr (cc1_plugin::connection *self,
     }
   tree res = identifier;
   if (!scope)
-    res = lookup_name_real (res, 0, 0, true, 0, 0);
+    res = lookup_name (res, LOOK_where::BLOCK_NAMESPACE);
   else if (!TYPE_P (scope) || !dependent_scope_p (scope))
     {
-      res = lookup_qualified_name (scope, res, false, true);
+      res = lookup_qualified_name (scope, res, LOOK_want::NORMAL, true);
       /* We've already resolved the name in the scope, so skip the
         build_qualified_name call below.  */
       scope = NULL;
@@ -2796,7 +2796,7 @@ plugin_build_unary_expr (cc1_plugin::connection *self,
       break;
 
     case THROW_EXPR:
-      result = build_throw (op0);
+      result = build_throw (input_location, op0);
       break;
 
     case TYPEID_EXPR:
@@ -2805,12 +2805,14 @@ plugin_build_unary_expr (cc1_plugin::connection *self,
 
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
-      result = cxx_sizeof_or_alignof_expr (op0, opcode, true);
+      result = cxx_sizeof_or_alignof_expr (input_location,
+                                          op0, opcode, true, true);
       break;
 
     case DELETE_EXPR:
     case VEC_DELETE_EXPR:
-      result = delete_sanity (op0, NULL_TREE, opcode == VEC_DELETE_EXPR,
+      result = delete_sanity (input_location, op0, NULL_TREE,
+                             opcode == VEC_DELETE_EXPR,
                              global_scope_p, tf_error);
       break;
 
@@ -3047,7 +3049,8 @@ plugin_build_unary_type_expr (cc1_plugin::connection *self,
 
     default:
       /* Use the C++11 alignof semantics.  */
-      result = cxx_sizeof_or_alignof_type (type, opcode, true, true);
+      result = cxx_sizeof_or_alignof_type (input_location, type,
+                                          opcode, true, true);
     }
 
   if (template_dependent_p)
@@ -3063,7 +3066,8 @@ plugin_build_cast_expr (cc1_plugin::connection *self,
                        gcc_expr operand2)
 {
   plugin_context *ctx = static_cast<plugin_context *> (self);
-  tree (*build_cast)(tree type, tree expr, tsubst_flags_t complain) = NULL;
+  tree (*build_cast)(location_t loc, tree type, tree expr,
+                    tsubst_flags_t complain) = NULL;
   tree type = convert_in (operand1);
   tree expr = convert_in (operand2);
 
@@ -3100,7 +3104,7 @@ plugin_build_cast_expr (cc1_plugin::connection *self,
   if (!template_dependent_p)
     processing_template_decl--;
 
-  tree val = build_cast (type, expr, tf_error);
+  tree val = build_cast (input_location, type, expr, tf_error);
 
   if (template_dependent_p)
     processing_template_decl--;
@@ -3154,7 +3158,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
@@ -3253,8 +3257,8 @@ plugin_build_new_expr (cc1_plugin::connection *self,
   if (!template_dependent_p)
     processing_template_decl--;
 
-  tree result = build_new (&placement, type, nelts, &initializer,
-                          global_scope_p, tf_error);
+  tree result = build_new (input_location, &placement, type, nelts,
+                          &initializer, global_scope_p, tf_error);
 
   if (template_dependent_p)
     processing_template_decl--;
@@ -3289,7 +3293,7 @@ plugin_build_call_expr (cc1_plugin::connection *self,
          fn = STRIP_TEMPLATE (fn);
 
          if (!DECL_FUNCTION_MEMBER_P (fn)
-             && !DECL_LOCAL_FUNCTION_P (fn))
+             && !DECL_LOCAL_DECL_P (fn))
            koenig_p = true;
        }
     }
@@ -3338,10 +3342,7 @@ plugin_get_expr_type (cc1_plugin::connection *self,
   if (op0)
     type = TREE_TYPE (op0);
   else
-    {
-      type = make_decltype_auto ();
-      AUTO_IS_DECLTYPE (type) = true;
-    }
+    type = make_decltype_auto ();
   return convert_out (ctx->preserve (type));
 }
 
@@ -3606,7 +3607,7 @@ plugin_build_constant (cc1_plugin::connection *self, gcc_type type_in,
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
   cp_finish_decl (decl, cst, true, NULL, LOOKUP_ONLYCONVERTING);
-  safe_pushdecl_maybe_friend (decl, false);
+  safe_pushdecl (decl);
 
   return 1;
 }
@@ -3641,7 +3642,7 @@ plugin_add_static_assert (cc1_plugin::connection *self,
 
   bool member_p = at_class_scope_p ();
 
-  finish_static_assert (condition, message, loc, member_p);
+  finish_static_assert (condition, message, loc, member_p, false);
 
   return 1;
 }