From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH to checking of explicit instantiation namespace
Date: Thu, 12 Nov 2015 20:37:00 -0000 [thread overview]
Message-ID: <5644F876.6070306@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 309 bytes --]
In the testcase, the using-declaration was confusing namespace
comparison into thinking that we were instantiating a template from an
enclosing namespace. Given using-declarations, we need to wait until
we've chosen a template before donig this comparison.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: inst-ns.patch --]
[-- Type: text/x-patch, Size: 1641 bytes --]
commit 43aa655785ca8da40d07e1320f532950fc9a83b5
Author: Jason Merrill <jason@redhat.com>
Date: Thu Nov 12 11:22:04 2015 -0500
* pt.c (check_explicit_specialization): Check the namespace after
we choose a template.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 62659ec..2e3d48b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2800,14 +2800,6 @@ check_explicit_specialization (tree declarator,
error ("%qD is not a template function", dname);
fns = error_mark_node;
}
- else
- {
- tree fn = OVL_CURRENT (fns);
- if (!is_associated_namespace (CP_DECL_CONTEXT (decl),
- CP_DECL_CONTEXT (fn)))
- error ("%qD is not declared in %qD",
- decl, current_namespace);
- }
}
declarator = lookup_template_function (fns, NULL_TREE);
@@ -2941,6 +2933,14 @@ check_explicit_specialization (tree declarator,
return error_mark_node;
else
{
+ if (!ctype && !was_template_id
+ && (specialization || member_specialization
+ || explicit_instantiation)
+ && !is_associated_namespace (CP_DECL_CONTEXT (decl),
+ CP_DECL_CONTEXT (tmpl)))
+ error ("%qD is not declared in %qD",
+ tmpl, current_namespace);
+
tree gen_tmpl = most_general_template (tmpl);
if (explicit_instantiation)
diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation4.C b/gcc/testsuite/g++.dg/template/explicit-instantiation4.C
new file mode 100644
index 0000000..72417b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/explicit-instantiation4.C
@@ -0,0 +1,7 @@
+void f();
+
+namespace A {
+ template <class T> void f(T) { }
+ using ::f;
+ template void f(int);
+}
reply other threads:[~2015-11-12 20:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5644F876.6070306@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).