build_base_path knows that it should limit what it tries to do within a template, but that handling wasn't being used within an NSDMI, only within a template function.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 7a11cba1268aa91df1bc253c43deb2dcbfd5b091 Author: Jason Merrill <ja...@redhat.com> Date: Sun Feb 19 15:55:10 2017 -0800 PR c++/79606 - ICE with this->base_member in NSDMI * class.c (build_base_path): Check processing_template_decl. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1442b55..9e4b4c4 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -375,6 +375,7 @@ build_base_path (enum tree_code code, set up properly yet, and the value doesn't matter there either; we're just interested in the result of overload resolution. */ if (cp_unevaluated_operand != 0 + || processing_template_decl || in_template_function ()) { expr = build_nop (ptr_target_type, expr); diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template16.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template16.C new file mode 100644 index 0000000..58dec7b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template16.C @@ -0,0 +1,14 @@ +// PR c++/79606 +// { dg-do compile { target c++11 } } + +struct A +{ + int i = 0; +}; + +template<int> struct B : A +{ + int j = this->i; +}; + +B<0> b;