Index: gcc/testsuite/g++.dg/lookup/using46.C
===================================================================
--- gcc/testsuite/g++.dg/lookup/using46.C	(revision 0)
+++ gcc/testsuite/g++.dg/lookup/using46.C	(revision 0)
@@ -0,0 +1,65 @@
+// PR c++/51141
+// { dg-do compile }
+// { dg-options "-fpermissive -w -Werror" }
+
+typedef int size_t;
+template < size_t, size_t > struct AlignedBuffer;
+template < size_t size > struct AlignedBuffer 
+         < size, 8 > {
+};
+
+template < typename > class VectorBufferBase
+{
+public:
+    allocateBuffer (size_t) {
+    }
+    buffer () {
+    }
+    *m_buffer;
+    size_t m_capacity;
+};
+
+template < typename T, size_t > class VectorBuffer:VectorBufferBase < T >
+{
+    typedef VectorBufferBase < T > Base;
+
+public:
+    VectorBuffer () {
+    }
+    allocateBuffer (size_t) {
+        m_capacity = 0;
+    }
+    Base::buffer;
+    Base::m_buffer;
+    Base::m_capacity;
+    size_t m_inlineBufferSize;
+
+    AlignedBuffer < 0, __alignof__ (T) > m_inlineBuffer;
+};
+
+template < typename T, size_t > class Vector
+{
+    typedef VectorBuffer < T,
+            0 > Buffer;
+public:
+    void shrinkCapacity (size_t);
+
+    clear () {
+        shrinkCapacity (0);
+    }
+    Buffer m_buffer;
+};
+
+template < typename T, size_t inlineCapacity > void Vector < T,
+         inlineCapacity >::shrinkCapacity (size_t)
+{
+    m_buffer.allocateBuffer (0);
+}
+
+struct PatternDisjunction;
+struct YarrPattern {
+    reset () {
+        m_disjunctions.clear ();
+    }
+    Vector < PatternDisjunction *, 0 > m_disjunctions;
+};
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 181386)
+++ gcc/cp/pt.c	(working copy)
@@ -13244,6 +13244,8 @@ tsubst_copy_and_build (tree t,
 	   failure, not NULL_TREE.  */
 	if (decl == NULL_TREE)
 	  decl = error_mark_node;
+	else
+	  decl = strip_using_decl (decl);
 
 	decl = finish_id_expression (t, decl, NULL_TREE,
 				     &idk,
