diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6f9380935086c691fa59edaf8ec803fdd815d522..3b0918af5d8fe67539d6744572ae602bd70c80b7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2012-11-16  Dodji Seketeli  <dodji@redhat.com>
+
+	PR c++/54875
+	* pt.c (lookup_template_class_1): Look at the type of the
+	potential member enum of class template to determine if we are
+	actually substituting into a member enum of class template.
+
 2012-11-16  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/55337
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3c9bb56c66baa7f75ca61f7de794abbce1b1178e..101b22d9bcfffde6e6483c40de388ab1326801e8 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/ChangeLog b/gcc/testsuite/ChangeLog
index d163db26f1bd52ac3db9bd88c5b609720fc4e313..314c2e4565af28b6267d65be31449627060ce29c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-11-16  Dodji Seketeli  <dodji@redhat.com>
+
+	PR c++/54875
+	* g++.dg/cpp0x/alias-decl-27.C: New test.
+
 2012-11-16  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/55337
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 0000000000000000000000000000000000000000..91208abf90eb9671f93b0fee4c33af85204bdca9
--- /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;
+}