This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix ICE in C++14 with null RETURN_EXPR (PR c++/65202)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 26 Feb 2015 15:12:41 +0100
- Subject: Re: [C++ PATCH] Fix ICE in C++14 with null RETURN_EXPR (PR c++/65202)
- Authentication-results: sourceware.org; auth=none
- References: <20150226122202 dot GD22272 at redhat dot com> <54EF2104 dot 7050901 at redhat dot com>
On Thu, Feb 26, 2015 at 08:35:00AM -0500, Jason Merrill wrote:
> On 02/26/2015 07:22 AM, Marek Polacek wrote:
> >- if (t == error_mark_node)
> >+ if (t == NULL_TREE || t == error_mark_node)
> > {
> > *non_constant_p = true;
>
> No, we don't want an empty return to make the call non-constant, it's
> perfectly valid. Let's handle this specifically in the RETURN_EXPR case.
Sorry about that. So like this?
2015-02-26 Marek Polacek <polacek@redhat.com>
PR c++/65202
* constexpr.c (cxx_eval_constant_expression): Don't evaluate
a RETURN_EXPR if its operand is null.
* g++.dg/cpp1y/pr65202.C: New test.
diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 32a23ff7..f7e8ce9 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -3113,9 +3113,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
break;
case RETURN_EXPR:
- r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
- lval,
- non_constant_p, overflow_p);
+ if (TREE_OPERAND (t, 0) != NULL_TREE)
+ r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
+ lval,
+ non_constant_p, overflow_p);
*jump_target = t;
break;
diff --git gcc/testsuite/g++.dg/cpp1y/pr65202.C gcc/testsuite/g++.dg/cpp1y/pr65202.C
index e69de29..602b264 100644
--- gcc/testsuite/g++.dg/cpp1y/pr65202.C
+++ gcc/testsuite/g++.dg/cpp1y/pr65202.C
@@ -0,0 +1,26 @@
+// // PR c++/65202
+// { dg-do compile { target c++14 } }
+
+template <typename T> struct is_move_constructible;
+template <typename T> struct is_move_assignable;
+template <int, typename T> using enable_if_t = int;
+namespace adl {
+template <
+ typename L, typename R,
+ enable_if_t<is_move_constructible<L>() && is_move_assignable<L>(), int>...>
+constexpr auto adl_swap(L &l, R &r) -> decltype(swap(l, r)) {
+ return;
+}
+template <typename L, typename R>
+auto swap(L &l, R &r) noexcept(noexcept(adl::adl_swap(l, r)))
+ -> decltype(adl::adl_swap(l, r));
+namespace ns {
+template <typename T> struct foo {};
+template <typename T> void swap(foo<T> &, foo<T> &);
+struct bar;
+
+int main()
+{
+ foo<ns::bar> f;
+ adl::swap(f, f)
+} // { dg-error "" }
Marek