PR c++/63283
* constexpr.c (potential_constant_expression_1): Handle reference
args in templates.
From-SVN: r219686
+2015-01-15 Jason Merrill <jason@redhat.com>
+
+ PR c++/63283
+ * constexpr.c (potential_constant_expression_1): Handle reference
+ args in templates.
+
2015-01-15 Thomas Schwinge <thomas@codesourcery.com>
James Norris <jnorris@codesourcery.com>
Cesar Philippidis <cesar@codesourcery.com>
for (; i < nargs; ++i)
{
tree x = get_nth_callarg (t, i);
- if (!RECUR (x, rval))
+ /* In a template, reference arguments haven't been converted to
+ REFERENCE_TYPE and we might not even know if the parameter
+ is a reference, so accept lvalue constants too. */
+ bool rv = processing_template_decl ? any : rval;
+ if (!RECUR (x, rv))
return false;
}
return true;
--- /dev/null
+// PR c++/63283
+// { dg-do compile { target c++11 } }
+
+constexpr int array_length(int (&array)[3]) { return 3; }
+int a[] = { 1, 2, 3 };
+template <typename T> int f() {
+ struct { int e[array_length(a)]; } t;
+ return sizeof(t);
+}
+int main() { f<void>(); }
template<typename T> bool foo(T)
{
int i;
- static_assert(foo(i), "Error"); // { dg-error "non-constant condition|not usable" }
+ static_assert(foo(i), "Error"); // { dg-error "non-constant condition|not usable|non-constexpr" }
}