public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Paolo Carlini <paolo.carlini@oracle.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ RFC / Patch] PR 51213 ("access control under SFINAE")
Date: Thu, 12 Jul 2012 23:06:00 -0000	[thread overview]
Message-ID: <4FFF587C.3050609@redhat.com> (raw)
In-Reply-To: <4FFF55EF.3090508@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

And here's a fix for the access7 failure, to be applied on top of your 
patch.

I notice that your patch changes the behavior of C++98/03 mode as well, 
which seems wrong to me; I think this is a big enough change that we 
should limit it to C++11 mode.

Jason


[-- Attachment #2: access7.patch --]
[-- Type: text/x-patch, Size: 3824 bytes --]

commit f60b940ab6bcbad60632ba085fa0a5cff2e963e3
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jul 12 17:16:35 2012 +0200

    access7

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8ce0f2a..12c688a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -78,6 +78,7 @@ c-common.h, not after.
       CONVERT_EXPR_VBASE_PATH (in CONVERT_EXPR)
       OVL_ARG_DEPENDENT (in OVERLOAD)
       PACK_EXPANSION_LOCAL_P (in *_PACK_EXPANSION)
+      TINFO_RECHECK_ACCESS_P (in TEMPLATE_INFO)
    1: IDENTIFIER_VIRTUAL_P (in IDENTIFIER_NODE)
       TI_PENDING_TEMPLATE_FLAG.
       TEMPLATE_PARMS_FOR_INLINE.
@@ -725,6 +726,14 @@ typedef struct qualified_typedef_usage_s qualified_typedef_usage_t;
 DEF_VEC_O (qualified_typedef_usage_t);
 DEF_VEC_ALLOC_O (qualified_typedef_usage_t,gc);
 
+/* Non-zero if this template specialization has access violations that
+   should be rechecked when the function is instantiated outside argument
+   deduction.  */
+#define TINFO_RECHECK_ACCESS_P(NODE) \
+  (TREE_LANG_FLAG_0 (TEMPLATE_INFO_CHECK (NODE)))
+#define FNDECL_RECHECK_ACCESS_P(NODE) \
+  (TINFO_RECHECK_ACCESS_P (DECL_TEMPLATE_INFO (NODE)))
+
 struct GTY(()) tree_template_info {
   struct tree_common common;
   VEC(qualified_typedef_usage_t,gc) *typedefs_needing_access_checking;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6a1780b..7eca5c7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -9875,10 +9875,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 	    hash = hash_tmpl_and_args (gen_tmpl, argvec);
 	    spec = retrieve_specialization (gen_tmpl, argvec, hash);
 
+	    r = spec;
 	    if (spec)
 	      {
-		r = spec;
-		break;
+		if (FNDECL_RECHECK_ACCESS_P (spec) && (complain & tf_error))
+		  /* Reinstantiate to get access errors.  */;
+		else
+		  break;
 	      }
 
 	    /* We can see more levels of arguments than parameters if
@@ -9954,6 +9957,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 	if (type == error_mark_node)
 	  RETURN (error_mark_node);
 
+	if (r)
+	  {
+	    /* We're done reinstantiating for access errors.  */
+	    gcc_assert (FNDECL_RECHECK_ACCESS_P (r));
+	    break;
+	  }
+
 	/* We do NOT check for matching decls pushed separately at this
 	   point, as they may not represent instantiations of this
 	   template, and in any case are considered separate under the
@@ -14347,7 +14357,13 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain)
 	      || fndecl == NULL_TREE);
 
   if (spec != NULL_TREE)
-    return spec;
+    {
+      if (FNDECL_RECHECK_ACCESS_P (spec)
+	  && (complain & tf_error))
+	/* Do the instantiation again, we're out of SFINAE context.  */;
+      else
+	return spec;
+    }
 
   if (check_instantiated_args (gen_tmpl, INNERMOST_TEMPLATE_ARGS (targ_ptr),
 			       complain))
@@ -14398,7 +14414,17 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain)
   if (DECL_CHAIN (gen_tmpl) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (gen_tmpl)))
     clone_function_decl (fndecl, /*update_method_vec_p=*/0);
 
-  return tmp ? error_mark_node : fndecl;
+  if (tmp)
+    {
+      if (!(complain & tf_error))
+	{
+	  /* Remember to reinstantiate when we're out of SFINAE so the user
+	     can see the errors.  */
+	  FNDECL_RECHECK_ACCESS_P (fndecl) = true;
+	}
+      return error_mark_node;
+    }
+  return fndecl;
 }
 
 /* Wrapper for instantiate_template_1.  */
diff --git a/gcc/testsuite/g++.dg/template/access7.C b/gcc/testsuite/g++.dg/template/access7.C
index bd38e4e..7d18127 100644
--- a/gcc/testsuite/g++.dg/template/access7.C
+++ b/gcc/testsuite/g++.dg/template/access7.C
@@ -14,5 +14,5 @@ typename A::T* f (A) {			// { dg-error "this context" }
 }
 
 void g () {
-  f (S<int> ());			// { dg-message "required" }
+  f (S<int> ());			// { dg-message "required|no match" }
 }

  reply	other threads:[~2012-07-12 23:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-15 14:57 Paolo Carlini
2012-06-28 10:38 ` Paolo Carlini
2012-07-02 19:48 ` Jason Merrill
2012-07-09 16:05   ` Jason Merrill
2012-07-12 15:26 ` Jason Merrill
2012-07-12 23:54 ` Jason Merrill
2012-07-12 23:06   ` Jason Merrill [this message]
2012-07-19  1:36     ` Jason Merrill
2012-07-19  9:45       ` Paolo Carlini
2012-07-14  9:57   ` Paolo Carlini
2012-07-16 18:53     ` Jason Merrill
2012-07-17 12:46       ` Paolo Carlini
2012-07-17 14:11         ` Jason Merrill
2012-07-17 16:14           ` Paolo Carlini
2012-07-18  1:20             ` Paolo Carlini
2012-07-18  2:47               ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FFF587C.3050609@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=paolo.carlini@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).