]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cp/pt.c
Make __PRETTY_FUNCTION__-like functions mergeable string csts (PR c++/64266).
[thirdparty/gcc.git] / gcc / cp / pt.c
index efed9a1bf60e92a911b2f9a3495eb0a6eb68bc71..2dc0cb1629cdc183273fd27b1677b5beb1b4a3eb 100644 (file)
@@ -7776,7 +7776,7 @@ convert_template_argument (tree parm,
   tree val;
   int is_type, requires_type, is_tmpl_type, requires_tmpl_type;
 
-  if (parm == error_mark_node)
+  if (parm == error_mark_node || error_operand_p (arg))
     return error_mark_node;
 
   /* Trivially convert placeholders. */
@@ -12803,6 +12803,28 @@ tsubst_default_arguments (tree fn, tsubst_flags_t complain)
                                                    complain);
 }
 
+/* Hash table mapping a FUNCTION_DECL to its dependent explicit-specifier.  */
+static GTY((cache)) tree_cache_map *explicit_specifier_map;
+
+/* Store a pair to EXPLICIT_SPECIFIER_MAP.  */
+
+void
+store_explicit_specifier (tree v, tree t)
+{
+  if (!explicit_specifier_map)
+    explicit_specifier_map = tree_cache_map::create_ggc (37);
+  DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (v) = true;
+  explicit_specifier_map->put (v, t);
+}
+
+/* Lookup an element in EXPLICIT_SPECIFIER_MAP.  */
+
+static tree
+lookup_explicit_specifier (tree v)
+{
+  return *explicit_specifier_map->get (v);
+}
+
 /* Subroutine of tsubst_decl for the case when T is a FUNCTION_DECL.  */
 
 static tree
@@ -12943,6 +12965,17 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
     DECL_INITIAL (r) = NULL_TREE;
   DECL_CONTEXT (r) = ctx;
 
+  /* Handle explicit(dependent-expr).  */
+  if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t))
+    {
+      tree spec = lookup_explicit_specifier (t);
+      spec = tsubst_copy_and_build (spec, args, complain, in_decl,
+                                   /*function_p=*/false,
+                                   /*i_c_e_p=*/true);
+      spec = build_explicit_specifier (spec, complain);
+      DECL_NONCONVERTING_P (r) = (spec == boolean_true_node);
+    }
+
   /* OpenMP UDRs have the only argument a reference to the declared
      type.  We want to diagnose if the declared type is a reference,
      which is invalid, but as references to references are usually
@@ -16702,6 +16735,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
            register_local_specialization (inst, decl);
            break;
          }
+       else if (DECL_PRETTY_FUNCTION_P (decl))
+         decl = make_fname_decl (DECL_SOURCE_LOCATION (decl),
+                                 DECL_NAME (decl),
+                                 true/*DECL_PRETTY_FUNCTION_P (decl)*/);
        else if (DECL_IMPLICIT_TYPEDEF_P (decl)
                 && LAMBDA_TYPE_P (TREE_TYPE (decl)))
          /* Don't copy the old closure; we'll create a new one in
@@ -16760,17 +16797,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
                                                   complain, in_decl, &first,
                                                   &cnt);
 
-                   if (VAR_P (decl)
-                       && DECL_PRETTY_FUNCTION_P (decl))
-                     {
-                       /* For __PRETTY_FUNCTION__ we have to adjust the
-                          initializer.  */
-                       const char *const name
-                         = cxx_printable_name (current_function_decl, 2);
-                       init = cp_fname_init (name, &TREE_TYPE (decl));
-                     }
-                   else
-                     init = tsubst_init (init, decl, args, complain, in_decl);
+                   init = tsubst_init (init, decl, args, complain, in_decl);
 
                    if (VAR_P (decl))
                      const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P
@@ -16815,6 +16842,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
         stmt = (processing_template_decl
                ? begin_range_for_stmt (NULL_TREE, NULL_TREE)
                : begin_for_stmt (NULL_TREE, NULL_TREE));
+       RECUR (RANGE_FOR_INIT_STMT (t));
         decl = RANGE_FOR_DECL (t);
         decl = tsubst (decl, args, complain, in_decl);
         maybe_push_decl (decl);
@@ -16832,6 +16860,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
            RANGE_FOR_IVDEP (stmt) = RANGE_FOR_IVDEP (t);
            RANGE_FOR_UNROLL (stmt) = RANGE_FOR_UNROLL (t);
            finish_range_for_decl (stmt, decl, expr);
+           if (decomp_first && decl != error_mark_node)
+             cp_finish_decomp (decl, decomp_first, decomp_cnt);
          }
        else
          {
@@ -23124,6 +23154,14 @@ do_decl_instantiation (tree decl, tree storage)
       error ("explicit instantiation of non-template %q#D", decl);
       return;
     }
+  else if (DECL_DECLARED_CONCEPT_P (decl))
+    {
+      if (VAR_P (decl))
+       error ("explicit instantiation of variable concept %q#D", decl);
+      else
+       error ("explicit instantiation of function concept %q#D", decl);
+      return;
+    }
 
   bool var_templ = (DECL_TEMPLATE_INFO (decl)
                     && variable_template_p (DECL_TI_TEMPLATE (decl)));
@@ -26077,7 +26115,7 @@ listify (tree arg)
   if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list))
     {    
       gcc_rich_location richloc (input_location);
-      maybe_add_include_fixit (&richloc, "<initializer_list>");
+      maybe_add_include_fixit (&richloc, "<initializer_list>", false);
       error_at (&richloc,
                "deducing from brace-enclosed initializer list"
                " requires %<#include <initializer_list>%>");
@@ -26118,7 +26156,7 @@ struct auto_hash : default_hash_traits<tree>
 inline hashval_t
 auto_hash::hash (tree t)
 {
-  if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t))
+  if (tree c = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (t)))
     /* Matching constrained-type-specifiers denote the same template
        parameter, so hash the constraint.  */
     return hash_placeholder_constraint (c);
@@ -26877,7 +26915,7 @@ do_auto_deduction (tree type, tree init, tree auto_node,
 
   /* Check any placeholder constraints against the deduced type. */
   if (flag_concepts && !processing_template_decl)
-    if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (auto_node))
+    if (tree constr = NON_ERROR (PLACEHOLDER_TYPE_CONSTRAINTS (auto_node)))
       {
         /* Use the deduced type to check the associated constraints. If we
            have a partial-concept-id, rebuild the argument list so that