diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3c9bb56..101b22d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7487,7 +7487,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
 	= tree_cons (arglist, t,
 		     DECL_TEMPLATE_INSTANTIATIONS (templ));
 
-      if (TREE_CODE (t) == ENUMERAL_TYPE && !is_dependent_type)
+      if (TREE_CODE (template_type) == ENUMERAL_TYPE && !is_dependent_type)
 	/* Now that the type has been registered on the instantiations
 	   list, we set up the enumerators.  Because the enumeration
 	   constants may involve the enumeration type itself, we make
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-27.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-27.C
new file mode 100644
index 0000000..91208ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-27.C
@@ -0,0 +1,11 @@
+// Origin: PR c++/54875
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+using AddConst = T const;
+
+enum FwdEnum : int;
+
+int main() {
+  AddConst<FwdEnum> *ptr = nullptr;
+}
