Hi! Most of the spots in tsubst_baselink that actually access baselink after it has been assigned lookup_fnfields () test that it is a BASELINK_P, except one - the BASELINK_OPTYPE update. lookup_fnfields can return error_mark_node though, perhaps something else too. The patch just follows what the surrounding code does.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-07-11 Jakub Jelinek <ja...@redhat.com> PR c++/71826 * pt.c (tsubst_baselink): Only set BASELINK_OPTYPE for BASELINK_P. * g++.dg/template/pr71826.C: New test. --- gcc/cp/pt.c.jj 2016-07-11 11:14:28.000000000 +0200 +++ gcc/cp/pt.c 2016-07-11 12:30:45.939554745 +0200 @@ -13734,7 +13734,8 @@ tsubst_baselink (tree baselink, tree obj BASELINK_FUNCTIONS (baselink), template_args); /* Update the conversion operator type. */ - BASELINK_OPTYPE (baselink) = optype; + if (BASELINK_P (baselink)) + BASELINK_OPTYPE (baselink) = optype; if (!object_type) object_type = current_class_type; --- gcc/testsuite/g++.dg/template/pr71826.C.jj 2016-07-11 12:34:51.406568756 +0200 +++ gcc/testsuite/g++.dg/template/pr71826.C 2016-07-11 12:33:35.000000000 +0200 @@ -0,0 +1,17 @@ +// PR c++/71826 +// { dg-do compile } + +template <class> struct A { int i; }; // { dg-message "note" } +struct B { void i () {} }; // { dg-message "note" } +template <class T> struct C : A <T>, B +{ + void f () { i (); } // { dg-error "is ambiguous" } +}; + +int +main () +{ + C <int> c; + c.f (); + return 0; +} Jakub