Hi,

here, when we don't see an initializer we believe we are surely dealing with a case of C++17 template argument deduction for class templates, but, in fact, it's just an ill-formed C++14 template variable specialization. Conveniently, we can use here too the predicate variable_template_specialization_p. Not 100% sure about the exact wording of the error message, I added '#' to %qD to explicitly print the auto-using type too.

Tested x86_64-linux.

Thanks, Paolo.

/////////////////////////

/cp
2019-02-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/84536
        * decl.c (cp_finish_decl): Do not ICE on a template variable
        specialization missing an initializer.

/testsuite
2019-02-17  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/84536
        * g++.dg/cpp1y/var-templ60.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 268968)
+++ cp/decl.c   (working copy)
@@ -6946,7 +6946,15 @@ cp_finish_decl (tree decl, tree init, bool init_co
     {
       tree d_init;
       if (init == NULL_TREE)
-       gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node));
+       {
+         if (variable_template_specialization_p (decl))
+           {
+             error ("initializer for %q#D is empty", decl);
+             TREE_TYPE (decl) = error_mark_node;
+             return;
+           }
+         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node));
+       }
       d_init = init;
       if (d_init)
        {
Index: testsuite/g++.dg/cpp1y/var-templ60.C
===================================================================
--- testsuite/g++.dg/cpp1y/var-templ60.C        (nonexistent)
+++ testsuite/g++.dg/cpp1y/var-templ60.C        (working copy)
@@ -0,0 +1,9 @@
+// PR c++/84536
+// { dg-do compile { target c++14 } }
+
+template<int... N> auto foo(N...);  // { dg-error "initializer" }
+
+void bar()
+{
+  foo<>();
+}

Reply via email to