aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-05-31 15:16:26 -0400
committerJason Merrill <jason@gcc.gnu.org>2016-05-31 15:16:26 -0400
commitf795360d35caef4aa3a17015f415e8f3b200a3e5 (patch)
treedca99a118f5909ca7413dd87d27a9d8a4ce9752b /gcc
parent3dc553dd32388c2d0528584d08d2d37538330462 (diff)
downloadgcc-f795360d35caef4aa3a17015f415e8f3b200a3e5.zip
gcc-f795360d35caef4aa3a17015f415e8f3b200a3e5.tar.gz
gcc-f795360d35caef4aa3a17015f415e8f3b200a3e5.tar.bz2
PR c++/71227 - specializing hidden friend
* pt.c (check_explicit_specialization): Give better diagnostic about specializing a hidden friend. From-SVN: r236941
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c16
-rw-r--r--gcc/testsuite/g++.dg/template/friend62.C16
3 files changed, 38 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0401255..35042bc 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2016-05-31 Jason Merrill <jason@redhat.com>
+
+ PR c++/71227
+ * pt.c (check_explicit_specialization): Give better diagnostic about
+ specializing a hidden friend.
+
2016-05-31 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/71248
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4a24c98..af37586 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2808,6 +2808,13 @@ check_explicit_specialization (tree declarator,
context. */
fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname,
false, true);
+ if (fns == error_mark_node)
+ /* If lookup fails, look for a friend declaration so we can
+ give a better diagnostic. */
+ fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname,
+ /*type*/false, /*complain*/true,
+ /*hidden*/true);
+
if (fns == error_mark_node || !is_overloaded_fn (fns))
{
error ("%qD is not a template function", dname);
@@ -2953,6 +2960,15 @@ check_explicit_specialization (tree declarator,
CP_DECL_CONTEXT (tmpl)))
error ("%qD is not declared in %qD",
tmpl, current_namespace);
+ else if (TREE_CODE (decl) == FUNCTION_DECL
+ && DECL_HIDDEN_FRIEND_P (tmpl))
+ {
+ if (pedwarn (DECL_SOURCE_LOCATION (decl), 0,
+ "friend declaration %qD is not visible to "
+ "explicit specialization", tmpl))
+ inform (DECL_SOURCE_LOCATION (tmpl),
+ "friend declaration here");
+ }
tree gen_tmpl = most_general_template (tmpl);
diff --git a/gcc/testsuite/g++.dg/template/friend62.C b/gcc/testsuite/g++.dg/template/friend62.C
new file mode 100644
index 0000000..c9796c4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend62.C
@@ -0,0 +1,16 @@
+// PR c++/71227
+// { dg-options "" }
+
+class A {
+ public:
+ template<typename T>
+ friend int f(int x, T v) { // { dg-message "declaration" }
+ return x + v;
+ }
+};
+
+
+template<>
+int f(int x, int v) { // { dg-warning "friend" }
+ return x + v;
+}