On Wed, Oct 16, 2019 at 04:36:07PM -0400, Jason Merrill wrote:
> > As for CLEANUP_STMT, I've tried it (the second patch), but it didn't change
> > anything, the diagnostics was still
> > constexpr-dtor3.C:16:23:   in ‘constexpr’ expansion of ‘f4()’
> > constexpr-dtor3.C:16:24:   in ‘constexpr’ expansion of ‘(& w13)->W7::~W7()’
> > constexpr-dtor3.C:5:34: error: inline assembly is not a constant expression
> >      5 |   constexpr ~W7 () { if (w == 5) asm (""); w = 3; } // { dg-error 
> > "inline assembly is not a constant expression" }
> >        |                                  ^~~
> > constexpr-dtor3.C:5:34: note: only unevaluated inline assembly is allowed 
> > in a ‘constexpr’ function in C++2a
> > as without that change.
> 
> That's because the patch changes EXPR_LOCATION for evaluation of the
> CLEANUP_BODY, but it should be for evaluation of CLEANUP_EXPR instead.

Indeed, that works too.  Bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk?

2019-10-18  Jakub Jelinek  <ja...@redhat.com>

        * constexpr.c (cxx_eval_constant_expression) <case CLEANUP_STMT>:
        Temporarily change input_location to CLEANUP_STMT location.

        * g++.dg/cpp2a/constexpr-dtor3.C: Expect in 'constexpr' expansion of
        message on the line with variable declaration.
        * g++.dg/ext/constexpr-attr-cleanup1.C: Likewise.

--- gcc/cp/constexpr.c.jj       2019-10-17 00:15:50.126726231 +0200
+++ gcc/cp/constexpr.c  2019-10-17 11:21:34.400062565 +0200
@@ -4984,14 +4984,20 @@ cxx_eval_constant_expression (const cons
                                          non_constant_p, overflow_p,
                                          jump_target);
        if (!CLEANUP_EH_ONLY (t) && !*non_constant_p)
-         /* Also evaluate the cleanup.  If we weren't skipping at the
-            start of the CLEANUP_BODY, change jump_target temporarily
-            to &initial_jump_target, so that even a return or break or
-            continue in the body doesn't skip the cleanup.  */
-         cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), true,
-                                       non_constant_p, overflow_p,
-                                       jump_target ? &initial_jump_target
-                                       : NULL);
+         {
+           location_t loc = input_location;
+           if (EXPR_HAS_LOCATION (t))
+             input_location = EXPR_LOCATION (t);
+           /* Also evaluate the cleanup.  If we weren't skipping at the
+              start of the CLEANUP_BODY, change jump_target temporarily
+              to &initial_jump_target, so that even a return or break or
+              continue in the body doesn't skip the cleanup.  */
+           cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), true,
+                                         non_constant_p, overflow_p,
+                                         jump_target ? &initial_jump_target
+                                         : NULL);
+           input_location = loc;
+         }
       }
       break;
 
--- gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C.jj     2019-10-17 
00:15:49.425736657 +0200
+++ gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C        2019-10-17 
11:20:13.977290046 +0200
@@ -149,7 +149,7 @@ constexpr int x3 = f3 ();
 constexpr int
 f4 ()
 {
-  W7 w13 = 5;
+  W7 w13 = 5;                  // { dg-message "in 'constexpr' expansion of" }
   return 0;
 }
 
--- gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C.jj       2019-10-03 
00:32:15.604526950 +0200
+++ gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C  2019-10-18 
00:18:50.248166117 +0200
@@ -15,7 +15,7 @@ cleanup2 (int *x)
 constexpr bool
 foo ()
 {
-  int a __attribute__((cleanup (cleanup))) = 1;
+  int a __attribute__((cleanup (cleanup))) = 1;        // { dg-message "in 
'constexpr' expansion of" }
   return true;
 }
 


        Jakub

Reply via email to