From 9c7b2b0ba8687f92f7beab2e3615a1107c7063db Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 17 Dec 2019 16:46:11 -0500 Subject: [PATCH] PR c++/92576 - redeclaration of variable template. The variable templates patch way back when forgot to add handling here. The simplest answer seems to be recursing to the underlying declaration. * decl.c (redeclaration_error_message): Recurse for variable templates. From-SVN: r279472 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 16 +++++----------- gcc/testsuite/g++.dg/cpp1y/var-templ32.C | 2 +- gcc/testsuite/g++.dg/cpp1y/var-templ65.C | 5 +++++ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ65.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e8a94f463e5..e5824d57cc0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-12-17 Jason Merrill + + PR c++/92576 - redeclaration of variable template. + * decl.c (redeclaration_error_message): Recurse for variable + templates. + 2019-12-17 Jason Merrill * name-lookup.c (get_std_name_hint): Add std::byte. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6dec5838303..86717dc8fed 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2977,20 +2977,14 @@ redeclaration_error_message (tree newdecl, tree olddecl) { tree nt, ot; - if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) - { - if (COMPLETE_TYPE_P (TREE_TYPE (newdecl)) - && COMPLETE_TYPE_P (TREE_TYPE (olddecl))) - return G_("redefinition of %q#D"); - return NULL; - } - if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL) return G_("redefinition of %q#D"); - if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL - || (DECL_TEMPLATE_RESULT (newdecl) - == DECL_TEMPLATE_RESULT (olddecl))) + if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL) + return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl), + DECL_TEMPLATE_RESULT (olddecl)); + + if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl)) return NULL; nt = DECL_TEMPLATE_RESULT (newdecl); diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ32.C b/gcc/testsuite/g++.dg/cpp1y/var-templ32.C index 80077a16b56..6767ff1d9c6 100644 --- a/gcc/testsuite/g++.dg/cpp1y/var-templ32.C +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ32.C @@ -4,4 +4,4 @@ template bool V1 = true; template -bool V1 = false; // { dg-error "primary template|not deducible" } +bool V1 = false; // { dg-error "primary template|redefinition|not deducible" } diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ65.C b/gcc/testsuite/g++.dg/cpp1y/var-templ65.C new file mode 100644 index 00000000000..10398bb793f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ65.C @@ -0,0 +1,5 @@ +// PR c++/84255 +// { dg-do compile { target c++14 } } + +template constexpr int var; +template constexpr int var = 1; // { dg-error "redefinition" } -- 2.30.2