https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59790
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed by r262637 and r262639
[PR c++/86374] Name lookup failure in enclosing template
https://gcc.gnu.org/ml/gcc-patches/2018-07/msg00701.html
PR c++/86374
* pt.c (lookup_template_class_1): Use tsubst_aggr_type for
contexts that are classes.
PR c++/86374
* g++.dg/pr86374.C: New.
