* C++ PATCH for c++/41972 (static data member argument to reference template parameter)
@ 2009-11-09 19:57 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2009-11-09 19:57 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 229 bytes --]
The code for checking valid template arguments didn't know that X::foo
will show up as a SCOPE_REF if we're currently in another template.
Tested x86_64-pc-linux-gnu, applied to trunk; will apply to 4.4 and 4.3
after testing.
[-- Attachment #2: 41972.patch --]
[-- Type: text/x-patch, Size: 1833 bytes --]
commit cbdac18988cbff2268e03364364f6289185d704a
Author: Jason Merrill <jason@redhat.com>
Date: Mon Nov 9 10:37:40 2009 -0500
PR c++/41972
* parser.c (cp_parser_template_argument): Accept SCOPE_REF around
VAR_DECL.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7bafb67..3475723 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11368,18 +11368,26 @@ cp_parser_template_argument (cp_parser* parser)
cp_parser_abort_tentative_parse (parser);
else
{
+ tree probe;
+
if (TREE_CODE (argument) == INDIRECT_REF)
{
gcc_assert (REFERENCE_REF_P (argument));
argument = TREE_OPERAND (argument, 0);
}
- if (TREE_CODE (argument) == VAR_DECL)
+ /* If we're in a template, we represent a qualified-id referring
+ to a static data member as a SCOPE_REF even if the scope isn't
+ dependent so that we can check access control later. */
+ probe = argument;
+ if (TREE_CODE (probe) == SCOPE_REF)
+ probe = TREE_OPERAND (probe, 1);
+ if (TREE_CODE (probe) == VAR_DECL)
{
/* A variable without external linkage might still be a
valid constant-expression, so no error is issued here
if the external-linkage check fails. */
- if (!address_p && !DECL_EXTERNAL_LINKAGE_P (argument))
+ if (!address_p && !DECL_EXTERNAL_LINKAGE_P (probe))
cp_parser_simulate_error (parser);
}
else if (is_overloaded_fn (argument))
diff --git a/gcc/testsuite/g++.dg/template/ref4.C b/gcc/testsuite/g++.dg/template/ref4.C
new file mode 100644
index 0000000..6d89fa8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ref4.C
@@ -0,0 +1,12 @@
+// PR c++/41972
+
+struct X {
+ static const double x;
+};
+template <const double& _test_>
+ class Foo { };
+template <typename _ignore_>
+struct Y {
+ typedef Foo<X::x> type;
+};
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-11-09 19:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-09 19:57 C++ PATCH for c++/41972 (static data member argument to reference template parameter) Jason Merrill
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).