public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/56208 (wrong sfinae with private inheritance)
@ 2013-02-06  3:28 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2013-02-06  3:28 UTC (permalink / raw)
  To: gcc-patches List

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

In this case, when we see the explicit template arguments for test and 
go to substitute them into the type of sfinae_base::test, we were 
recording that we wanted to check access to sfinae_base::make in the 
context of is_printable, but then by the time we got around to checking 
it we had pushed into the context of sfinae_base which doesn't have the 
right to see make by way of is_printable.  Fixed by discarding any 
deferred access checks from explicit template argument substitution, 
because we'll get the same access checks when we substitute in all the 
template arguments in instantiate_template, and those will have the 
right access path.

Tested x86_64-pc-linux-gnu, applying to trunk.

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

commit a194a47d7bc3bbdc362ba78cbb30fc493b9a3fdb
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 5 14:01:41 2013 -0500

    	PR c++/56208
    	* pt.c (fn_type_unification): Discard any access checks from
    	substituting explicit args.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 7430289..aa127ed 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14989,6 +14989,12 @@ fn_type_unification (tree fn,
       if (fntype == error_mark_node)
 	goto fail;
 
+      /* Throw away these access checks; we'll see them again in
+	 instantiate_template and they might have the wrong
+	 access path at this point.  */
+      pop_deferring_access_checks ();
+      push_deferring_access_checks (dk_deferred);
+
       /* Place the explicitly specified arguments in TARGS.  */
       for (i = NUM_TMPL_ARGS (explicit_targs); i--;)
 	TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (explicit_targs, i);
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae43.C b/gcc/testsuite/g++.dg/cpp0x/sfinae43.C
new file mode 100644
index 0000000..22efe65
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae43.C
@@ -0,0 +1,31 @@
+// PR c++/56208
+// { dg-options -std=c++11 }
+
+struct ostream {
+  ostream& operator<<(int);
+};
+
+struct sfinae_base {
+
+  typedef char one;
+  typedef char (&two)[2];
+
+  template<class T>
+  static T make();
+
+  template<unsigned> struct ok { typedef int type; };
+
+  template<class U, class T>
+  static one test(decltype((make<U>() << make<T>()), 0));
+
+  template<class, class>
+  static two test(...);
+};
+
+template<class T>
+struct is_printable : private sfinae_base
+{
+  enum { value = sizeof(test<ostream&, T>(0)) == sizeof(one) };
+};
+
+typedef int ok[is_printable<int>::value ? 1 : -1];

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-02-06  3:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06  3:28 C++ PATCH for c++/56208 (wrong sfinae with private inheritance) Jason Merrill

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).