diff mbox

C++ PATCH for c++/78906 (ICE with member template variable)

Message ID CADzB+2mdpFhyUn3L+z9qyc1eW37uLcno-VOAxc+YMqFNiDLkSQ@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Dec. 22, 2016, 8:26 p.m. UTC
If we're adding the enclosing template args, we also need to switch to
looking at the most general template.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 35fe583ade362f018f095435980424f1244ab92f
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 22 13:27:26 2016 -0500

            PR c++/78906 - ICE with member variable template
    
            * pt.c (finish_template_variable): Use most_general_template.
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 7711546..3fa2ce9 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -9000,6 +9000,7 @@  finish_template_variable (tree var, tsubst_flags_t complain)
   tree tmpl_args = DECL_TI_ARGS (DECL_TEMPLATE_RESULT (templ));
   arglist = add_outermost_template_args (tmpl_args, arglist);
 
+  templ = most_general_template (templ);
   tree parms = DECL_TEMPLATE_PARMS (templ);
   arglist = coerce_innermost_template_parms (parms, arglist, templ, complain,
 					     /*req_all*/true,
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ54.C b/gcc/testsuite/g++.dg/cpp1y/var-templ54.C
new file mode 100644
index 0000000..f52f764
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ54.C
@@ -0,0 +1,13 @@ 
+// PR c++/78906
+// { dg-do compile { target c++14 } }
+
+template <typename> struct A { static constexpr int digits = 0; };
+template <typename> struct B {
+  template <int, typename MaskInt = int, int = A<MaskInt>::digits>
+  static constexpr int XBitMask = 0;
+};
+struct C {
+  using ReferenceHost = B<int>;
+  template <int> static decltype(ReferenceHost::XBitMask<0>) XBitMask;
+};
+int main() { C::XBitMask<0>; }