PR c++/63283
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Jan 2015 20:46:03 +0000 (20:46 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Jan 2015 20:46:03 +0000 (20:46 +0000)
* constexpr.c (potential_constant_expression_1): Handle reference
args in templates.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219686 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-template8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/static_assert10.C

index 543f4d9..7ad7737 100644 (file)
@@ -1,3 +1,9 @@
+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>
index 1432506..e27a892 100644 (file)
@@ -3881,7 +3881,11 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
         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;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template8.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template8.C
new file mode 100644 (file)
index 0000000..7b2b9c7
--- /dev/null
@@ -0,0 +1,10 @@
+// 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>(); }
index 216f259..e7f728e 100644 (file)
@@ -4,5 +4,5 @@
 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" }
 }