aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-08-25 22:47:42 -0400
committerJason Merrill <jason@gcc.gnu.org>2014-08-25 22:47:42 -0400
commit991eeb496254f48c059f8b9ddb587ee91bf3be96 (patch)
tree2e5652c761d9e4156c3c97c6d2c3fdc91cb467c0
parentf348033d1e1df30e6238506bee3a154a852a96d3 (diff)
downloadgcc-991eeb496254f48c059f8b9ddb587ee91bf3be96.zip
gcc-991eeb496254f48c059f8b9ddb587ee91bf3be96.tar.gz
gcc-991eeb496254f48c059f8b9ddb587ee91bf3be96.tar.bz2
pt.c (check_explicit_specialization): Don't complain about non-template variable.
* pt.c (check_explicit_specialization): Don't complain about non-template variable. (template_for_substitution): Allow variable templates. (check_template_variable): Fix logic for member var template. * decl.c (start_decl): Don't complain about extra template header here. From-SVN: r214487
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/decl.c8
-rw-r--r--gcc/cp/pt.c16
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/var-templ10.C16
4 files changed, 30 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d9bf905..04394c3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,12 @@
2014-08-25 Jason Merrill <jason@redhat.com>
+ * pt.c (check_explicit_specialization): Don't complain about
+ non-template variable.
+ (template_for_substitution): Allow variable templates.
+ (check_template_variable): Fix logic for member var template.
+ * decl.c (start_decl): Don't complain about extra template header
+ here.
+
* decl.c (start_decl): Look through member variable template.
* pt.c (tsubst_decl) [VAR_DECL]: Handle member variable templates.
* decl2.c (grokfield): Set DECL_CONTEXT earlier on
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 80696dd..d03f8a4 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4672,14 +4672,6 @@ start_decl (const cp_declarator *declarator,
}
field = DECL_TEMPLATE_RESULT (field);
}
- else if (this_tmpl)
- {
- error_at (DECL_SOURCE_LOCATION (decl),
- "member template declaration of %qD", decl);
- inform (DECL_SOURCE_LOCATION (field), "does not match "
- "non-member-template declaration here");
- return error_mark_node;
- }
if (DECL_CONTEXT (field) != context)
{
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3e6d777..59df387 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2308,7 +2308,8 @@ check_template_variable (tree decl)
{
tree ctx = CP_DECL_CONTEXT (decl);
int wanted = num_template_headers_for_class (ctx);
- if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx))
+ if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
+ && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
{
if (cxx_dialect < cxx14)
pedwarn (DECL_SOURCE_LOCATION (decl), 0,
@@ -2323,7 +2324,8 @@ check_template_variable (tree decl)
bool warned = pedwarn (DECL_SOURCE_LOCATION (decl), 0,
"too many template headers for %D (should be %d)",
decl, wanted);
- if (warned && CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
+ if (warned && CLASS_TYPE_P (ctx)
+ && CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
inform (DECL_SOURCE_LOCATION (decl),
"members of an explicitly specialized class are defined "
"without a template header");
@@ -2451,11 +2453,9 @@ check_explicit_specialization (tree declarator,
/* Fall through. */
case tsk_expl_spec:
if (VAR_P (decl) && TREE_CODE (declarator) != TEMPLATE_ID_EXPR)
- {
- // In cases like template<> constexpr bool v = true;
- error ("%qD is not a template variable", dname);
- break;
- }
+ /* In cases like template<> constexpr bool v = true;
+ We'll give an error in check_template_variable. */
+ break;
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
if (ctype)
@@ -19711,8 +19711,6 @@ template_for_substitution (tree decl)
cannot restructure the loop to just keep going until we find
a template with a definition, since that might go too far if
a specialization was declared, but not defined. */
- gcc_assert (!VAR_P (decl)
- || DECL_IN_AGGR_P (DECL_TEMPLATE_RESULT (tmpl)));
/* Fetch the more general template. */
tmpl = DECL_TI_TEMPLATE (tmpl);
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ10.C b/gcc/testsuite/g++.dg/cpp1y/var-templ10.C
new file mode 100644
index 0000000..ece2eb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ10.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++14 } }
+
+template <class T>
+struct Y
+{
+ template <class U> static U x;
+};
+
+template <class T>
+template <class U>
+U Y<T>::x = U();
+
+int main()
+{
+ int y = Y<int>::x<int>;
+}