From 080384d6057018108dd588b456ed53ec0b752769 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 27 Feb 2017 15:17:17 -0500 Subject: [PATCH] PR c++/71568 - SFINAE forming pointer to member function * init.c (build_offset_ref): Check the return value of perform_or_defer_access_check. From-SVN: r245763 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/init.c | 25 +++++++++++++++---------- gcc/testsuite/g++.dg/cpp0x/sfinae58.C | 12 ++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/sfinae58.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 03f92565772..5792e5d08d0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-02-27 Jason Merrill + + PR c++/71568 - SFINAE forming pointer to member function + * init.c (build_offset_ref): Check the return value of + perform_or_defer_access_check. + 2017-02-27 Marek Polacek * decl.c (expand_static_init): Add missing } in a comment. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b8308227988..99eeb8a893f 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2043,14 +2043,16 @@ build_offset_ref (tree type, tree member, bool address_p, If the access is to form a pointer to member, the nested-name-specifier shall name the derived class (or any class derived from that class). */ + bool ok; if (address_p && DECL_P (t) && DECL_NONSTATIC_MEMBER_P (t)) - perform_or_defer_access_check (TYPE_BINFO (type), t, t, - complain); + ok = perform_or_defer_access_check (TYPE_BINFO (type), t, t, + complain); else - perform_or_defer_access_check (basebinfo, t, t, - complain); - + ok = perform_or_defer_access_check (basebinfo, t, t, + complain); + if (!ok) + return error_mark_node; if (DECL_STATIC_FUNCTION_P (t)) return t; member = t; @@ -2059,11 +2061,14 @@ build_offset_ref (tree type, tree member, bool address_p, TREE_TYPE (member) = unknown_type_node; } else if (address_p && TREE_CODE (member) == FIELD_DECL) - /* We need additional test besides the one in - check_accessibility_of_qualified_id in case it is - a pointer to non-static member. */ - perform_or_defer_access_check (TYPE_BINFO (type), member, member, - complain); + { + /* We need additional test besides the one in + check_accessibility_of_qualified_id in case it is + a pointer to non-static member. */ + if (!perform_or_defer_access_check (TYPE_BINFO (type), member, member, + complain)) + return error_mark_node; + } if (!address_p) { diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae58.C b/gcc/testsuite/g++.dg/cpp0x/sfinae58.C new file mode 100644 index 00000000000..aaa38d3ed06 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae58.C @@ -0,0 +1,12 @@ +// PR c++/71568 +// { dg-do compile { target c++11 } } + +template class F : T {}; +template using void_t = void; +template struct G; +template struct G> {}; +struct D { + void nlog_custom(); +}; +G> g; // { dg-error "incomplete" } + -- 2.30.2