This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/47200 (ICE with undefined constexpr fn)


Once we've decided that we aren't dealing with a constant expression, we shouldn't assume that constraints are met.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit dfc46ac8095fd68129ecb76d24dc58906db71e71
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Mar 1 17:31:27 2011 -0500

    	PR c++/47200
    	* semantics.c (cxx_bind_parameters_in_call): Don't call
    	adjust_temp_type on non-constant args.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a33a7ed..6b3e914 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5906,6 +5906,9 @@ cxx_bind_parameters_in_call (const constexpr_call *old_call, tree t,
       /* Just discard ellipsis args after checking their constantitude.  */
       if (!parms)
 	continue;
+      if (*non_constant_p)
+	/* Don't try to adjust the type of non-constant args.  */
+	goto next;
 
       /* Make sure the binding has the same type as the parm.  */
       if (TREE_CODE (type) != REFERENCE_TYPE)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-non-const-arg2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-non-const-arg2.C
new file mode 100644
index 0000000..20e05c3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-non-const-arg2.C
@@ -0,0 +1,16 @@
+// PR c++/47200
+// { dg-options "-std=c++0x -w" }
+
+template < int > struct duration
+{
+  constexpr int count ();
+  static constexpr duration min ();
+};
+
+constexpr int
+f (duration < 0 > d, duration < 0 > )
+{
+  return d.count ();
+}
+
+static_assert (f (duration < 0 >::min (), duration < 0 > ()), ""); // { dg-error "non-constant|before its definition" }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]