This is an instance where we were failing to canonicalize a template
argument: for an integer constant, we need to make sure that it has the
type of the template parameter, rather than possibly a typedef local to
another template.
Tested x86_64-pc-linux-gnu, applying to trunk, 4.8, 4.7.
commit 1f06a84c5f6716cbc23498eeb9a4dfff1203b516
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Jul 9 02:26:39 2013 -0400
PR c++/57545
* pt.c (convert_nontype_argument) [INTEGER_CST]: Force the
argument to have the exact type of the parameter.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 23229a9..877d3b7 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5620,6 +5620,10 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
else
return NULL_TREE;
}
+
+ /* Avoid typedef problems. */
+ if (TREE_TYPE (expr) != type)
+ expr = fold_convert (type, expr);
}
/* [temp.arg.nontype]/5, bullet 2
diff --git a/gcc/testsuite/g++.dg/debug/template2.C b/gcc/testsuite/g++.dg/debug/template2.C
new file mode 100644
index 0000000..9f5bcd9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/template2.C
@@ -0,0 +1,14 @@
+// PR c++/57545
+
+template<typename T, long unsigned int N>
+struct array {
+ T data[N];
+};
+
+template<typename T>
+struct derived {
+ typedef long unsigned int size_type;
+ static const size_type n = 42;
+
+ array<int, n> a;
+};