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]

Re: C++ PATCH to fix ICE in generic lambda with user-defined conversion (PR c++/84125)


On Thu, Feb 01, 2018 at 02:35:08PM -0500, Jason Merrill wrote:
> On Tue, Jan 30, 2018 at 3:18 PM, Marek Polacek <polacek@redhat.com> wrote:
> > This testcase breaks since r256550 because we end up trying to build_address of
> > a CONSTRUCTOR, but that doesn't work because we hit
> >   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR);
> >
> > finish_static_assert gets {} as 'condition'.
> 
> Well, it gets X{}.
> 
> > In the testcase we have a
> > user-defined conversion, so {} should be turned to false, via
> > perform_implicit_conversion_flags -> ... -> build_user_type_conversion_1, but
> > that crashes as explained above.
> >
> > This only happens while processing generic lambda because processing_template_decl is 1,
> > so finish_compound_literal returns {} instead of a TARGET_EXPR.
> 
> So I think we should disable the above assert if
> processing_template_decl; the CONSTRUCTOR is actually fine here.

Thanks.  So like this?

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-02-01  Marek Polacek  <polacek@redhat.com>

	PR c++/84125
	* typeck.c (build_address): Relax the assert when
	processing_template_decl.

	* g++.dg/cpp1y/lambda-generic-84125.C:New test.

diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index 1102f677f15..83e76782998 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -5735,7 +5735,8 @@ build_address (tree t)
 {
   if (error_operand_p (t) || !cxx_mark_addressable (t))
     return error_mark_node;
-  gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR);
+  gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR
+		       || processing_template_decl);
   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
   if (TREE_CODE (t) != ADDR_EXPR)
     t = rvalue (t);
diff --git gcc/testsuite/g++.dg/cpp1y/lambda-generic-84125.C gcc/testsuite/g++.dg/cpp1y/lambda-generic-84125.C
index e69de29bb2d..8bf6a09652e 100644
--- gcc/testsuite/g++.dg/cpp1y/lambda-generic-84125.C
+++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-84125.C
@@ -0,0 +1,10 @@
+// PR c++/84125
+// { dg-do compile { target c++14 } }
+
+struct X { constexpr operator bool() const { return true; } };
+
+int main(){
+    [](auto) {
+        static_assert(X{}, "");
+    };
+}

	Marek


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