* class.c (pushclass): Accept NULL argument.
(popclass): Deal with popping null class.
* pt.c (push_access_scope, pop_access_scope): Use them rather than
push_to_top_level/pop_from_top_level.
(push_deduction_access_scope, pop_defarg_context): New.
(fn_type_unification): Use them.
* name-lookup.c (lookup_name_real_1): Check current_class_type.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174139
138bc75d-0d04-0410-961f-
82ee72b054a4
+2011-05-24 Jason Merrill <jason@redhat.com>
+
+ PR c++/48884
+ * class.c (pushclass): Accept NULL argument.
+ (popclass): Deal with popping null class.
+ * pt.c (push_access_scope, pop_access_scope): Use them rather than
+ push_to_top_level/pop_from_top_level.
+ (push_deduction_access_scope, pop_defarg_context): New.
+ (fn_type_unification): Use them.
+ * name-lookup.c (lookup_name_real_1): Check current_class_type.
+
2011-05-24 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (grokdeclarator): Use current_class_name.
So that we may avoid calls to lookup_name, we cache the _TYPE
nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
+ For use by push_access_scope, we allow TYPE to be null to temporarily
+ push out of class scope. This does not actually change binding levels.
+
For multiple inheritance, we perform a two-pass depth-first search
of the type lattice. */
{
class_stack_node_t csn;
- type = TYPE_MAIN_VARIANT (type);
-
/* Make sure there is enough room for the new entry on the stack. */
if (current_class_depth + 1 >= current_class_stack_size)
{
csn->hidden = 0;
current_class_depth++;
+ if (type == NULL_TREE)
+ {
+ current_class_name = current_class_type = NULL_TREE;
+ csn->hidden = true;
+ return;
+ }
+
+ type = TYPE_MAIN_VARIANT (type);
+
/* Now set up the new type. */
current_class_name = TYPE_NAME (type);
if (TREE_CODE (current_class_name) == TYPE_DECL)
void
popclass (void)
{
- poplevel_class ();
+ if (current_class_type)
+ poplevel_class ();
+ else
+ gcc_assert (current_class_depth
+ && current_class_stack[current_class_depth - 1].hidden);
current_class_depth--;
current_class_name = current_class_stack[current_class_depth].name;
/* Conversion operators are handled specially because ordinary
unqualified name lookup will not find template conversion
operators. */
- if (IDENTIFIER_TYPENAME_P (name))
+ if (IDENTIFIER_TYPENAME_P (name) && current_class_type)
{
struct cp_binding_level *level;
else if (DECL_CLASS_SCOPE_P (t))
push_nested_class (DECL_CONTEXT (t));
else
- push_to_top_level ();
+ pushclass (NULL_TREE);
if (TREE_CODE (t) == FUNCTION_DECL)
{
if (DECL_FRIEND_CONTEXT (t) || DECL_CLASS_SCOPE_P (t))
pop_nested_class ();
else
- pop_from_top_level ();
+ popclass ();
}
/* Do any processing required when DECL (a member template
return ret;
}
+/* We're going to do deduction substitution on the type of TMPL, a function
+ template. In C++11 mode, push into that access scope. In C++03 mode,
+ disable access checking. */
+
+static void
+push_deduction_access_scope (tree tmpl)
+{
+ if (cxx_dialect >= cxx0x)
+ push_access_scope (DECL_TEMPLATE_RESULT (tmpl));
+ else
+ push_deferring_access_checks (dk_no_check);
+}
+
+/* And pop back out. */
+
+static void
+pop_deduction_access_scope (tree tmpl)
+{
+ if (cxx_dialect >= cxx0x)
+ pop_access_scope (DECL_TEMPLATE_RESULT (tmpl));
+ else
+ pop_deferring_access_checks ();
+}
+
/* The FN is a TEMPLATE_DECL for a function. ARGS is an array with
NARGS elements of the arguments that are being used when calling
it. TARGS is a vector into which the deduced template arguments
incomplete = NUM_TMPL_ARGS (explicit_targs) != NUM_TMPL_ARGS (targs);
processing_template_decl += incomplete;
+ push_deduction_access_scope (fn);
fntype = deduction_tsubst_fntype (fn, converted_args);
+ pop_deduction_access_scope (fn);
processing_template_decl -= incomplete;
if (fntype == error_mark_node)
substitution results in an invalid type, as described above,
type deduction fails. */
{
- tree substed = deduction_tsubst_fntype (fn, targs);
+ tree substed;
+ push_deduction_access_scope (fn);
+ substed = deduction_tsubst_fntype (fn, targs);
+ pop_deduction_access_scope (fn);
if (substed == error_mark_node)
return 1;
+2011-05-24 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/template/access21.C: New.
+ * g++.dg/template/access22.C: New.
+
2011-05-24 Michael Matz <matz@gcc.gnu.org>
PR rtl-optimization/48633
--- /dev/null
+// PR c++/48884
+
+class X
+{
+ static const int I = 42;
+ friend struct Y;
+};
+
+template <int I> struct A { };
+
+struct Y
+{
+ template <typename T>
+ static A<T::I> f(T t)
+ {
+ return A<T::I>();
+ }
+};
+
+int main()
+{
+ Y::f(X());
+}
--- /dev/null
+template <int I> struct B { };
+
+template <class T>
+B<T::I> f();
+
+class A
+{
+ static const int I = 42;
+ template <class T> friend B<T::I> f();
+};
+
+int main()
+{
+ f<A>();
+}