From 742b0bcd66e1d8d40b19e33bf86764bbd3aa1744 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 2 Aug 2012 14:44:58 -0400 Subject: [PATCH] PR c++/51213 (again) /cp 2012-08-02 Jason Merrill Paolo Carlini PR c++/51213 (again) * pt.c (type_unification_real): Call push_deferring_access_checks / pop_deferring_access_checks around the substitution of default template args. (instantiate_template_1): When the specialization returned by retrieve_specialization has FNDECL_HAS_ACCESS_ERRORS set and we are in a SFINAE context, simply return error_mark_node. * cp-tree.h (FNDECL_RECHECK_ACCESS_P): Rename FNDECL_HAS_ACCESS_ERRORS. /testsuite 2012-08-02 Jason Merrill Paolo Carlini PR c++/51213 (again) * g++.dg/cpp0x/sfinae37.C: Extend. Co-Authored-By: Paolo Carlini From-SVN: r190093 --- gcc/cp/ChangeLog | 12 ++++++++++++ gcc/cp/cp-tree.h | 6 +++--- gcc/cp/pt.c | 12 +++++++++--- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/sfinae37.C | 14 ++++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8c2272e9d53..92c9db1a99e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2012-08-02 Jason Merrill + Paolo Carlini + + PR c++/51213 (again) + * pt.c (type_unification_real): Call push_deferring_access_checks / + pop_deferring_access_checks around the substitution of default + template args. + (instantiate_template_1): When the specialization returned by + retrieve_specialization has FNDECL_HAS_ACCESS_ERRORS set and we + are in a SFINAE context, simply return error_mark_node. + * cp-tree.h (FNDECL_RECHECK_ACCESS_P): Rename FNDECL_HAS_ACCESS_ERRORS. + 2012-07-31 Paolo Carlini * pt.c (check_default_tmpl_args): Change is_primary and is_partial diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ec33d92ad92..e40f11482e7 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -729,10 +729,10 @@ 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) \ +#define TINFO_HAS_ACCESS_ERRORS(NODE) \ (TREE_LANG_FLAG_0 (TEMPLATE_INFO_CHECK (NODE))) -#define FNDECL_RECHECK_ACCESS_P(NODE) \ - (TINFO_RECHECK_ACCESS_P (DECL_TEMPLATE_INFO (NODE))) +#define FNDECL_HAS_ACCESS_ERRORS(NODE) \ + (TINFO_HAS_ACCESS_ERRORS (DECL_TEMPLATE_INFO (NODE))) struct GTY(()) tree_template_info { struct tree_common common; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6257502ac1e..2ae576d7f18 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14363,8 +14363,12 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) if (spec != NULL_TREE) { - if (FNDECL_RECHECK_ACCESS_P (spec) && (complain & tf_error)) - recheck_decl_substitution (spec, gen_tmpl, targ_ptr); + if (FNDECL_HAS_ACCESS_ERRORS (spec)) + { + if (complain & tf_error) + recheck_decl_substitution (spec, gen_tmpl, targ_ptr); + return error_mark_node; + } return spec; } @@ -14426,7 +14430,7 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) { /* Remember to reinstantiate when we're out of SFINAE so the user can see the errors. */ - FNDECL_RECHECK_ACCESS_P (fndecl) = true; + FNDECL_HAS_ACCESS_ERRORS (fndecl) = true; } return error_mark_node; } @@ -15122,9 +15126,11 @@ type_unification_real (tree tparms, location_t save_loc = input_location; if (DECL_P (parm)) input_location = DECL_SOURCE_LOCATION (parm); + push_deferring_access_checks (dk_no_deferred); arg = tsubst_template_arg (arg, targs, complain, NULL_TREE); arg = convert_template_argument (parm, arg, targs, complain, i, NULL_TREE); + pop_deferring_access_checks (); input_location = save_loc; if (arg == error_mark_node) return 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3941926ab49..14659cd123e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2012-08-02 Jason Merrill + Paolo Carlini + + PR c++/51213 (again) + * g++.dg/cpp0x/sfinae37.C: Extend. + 2012-08-02 Richard Guenther PR tree-optimization/50672 diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae37.C b/gcc/testsuite/g++.dg/cpp0x/sfinae37.C index 071923e5261..e89106aac34 100644 --- a/gcc/testsuite/g++.dg/cpp0x/sfinae37.C +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae37.C @@ -5,6 +5,12 @@ class C { typedef int type; }; +template +struct I; + +template<> +struct I<2> { }; + template auto f(int) -> char; @@ -13,6 +19,10 @@ auto f(...) -> char (&)[2]; static_assert(sizeof(f(0)) == 2, "Ouch"); +typedef int testf[sizeof(f(0)) == 2 ? 1 : -1]; + +I(0))> vf; + template auto g(int) -> decltype(typename T::type(), char()); @@ -20,3 +30,7 @@ template auto g(...) -> char (&)[2]; static_assert(sizeof(g(0)) == 2, "Ouch"); + +typedef int testg[sizeof(g(0)) == 2 ? 1 : -1]; + +I(0))> vg;