Possible C++ template instantiation bug?

Dear clang developers,

I was investigating whether our computer simulation library
LibGeoDecomp would work with clang++, when I noticed that some of the
unit tests were failing. Apparently clang++ handles partial
specialization of member function templates in combination with
inheritance differently from other compilers (e.g. g++ and icpc).

I've tried to come up with a minimal test program which reproduces the
odd behavior (attached). Having been pruned so much, the program
itself doesn't make much sense. It was originally part of our code
which handles boundary conditions. IMHO the program should yield the
output "function2" twice, but with clang++ I get "function5" for the
first invocation. Is this a bug in clang++, or is this simply
undefined behavior?

Reproduction:

test3.cpp (1.74 KB)

Filed under http://llvm.org/bugs/show_bug.cgi?id=16936