public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94676] New: constexpr destructors run too late for temporaries created inside __builtin_constant_p
@ 2020-04-21  4:34 richard-gccbugzilla at metafoo dot co.uk
  2020-04-21  7:24 ` [Bug c++/94676] " redi at gcc dot gnu.org
  2020-04-21  7:44 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-04-21  4:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94676

            Bug ID: 94676
           Summary: constexpr destructors run too late for temporaries
                    created inside __builtin_constant_p
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

Testcase:


struct A {
  int *p;
  constexpr ~A() { *p = 0; }
};
static_assert(!__builtin_constant_p((A{}, 123)));


I think this testcase should be accepted. The way I see it, there are two ways
one could approach this:

1) Run the destructor for the A temporary after evaluating
__builtin_constant_p's operand, notice the operand is non-constant, and
evaluate the __bcp call to 0.

2) Notice that the __bcp call's operand has a side-effect on the enclosing
evaluation (registering a non-trivial destructor for a temporary) and evaluate
the call to 0 due to that side-effect. [This is what Clang currently does.]

I was considering changing Clang's behavior from option 2 to option 1, but I
noticed that GCC actually appears to do a third thing:

3) Run the destructor at the end of the entire static-assert condition and
reject the program because the destructor (run outside of the protection of
__builtin_constant_p) has a side-effect.

I don't think there's an obvious correct answer here, but (3) doesn't seem
right to me.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/94676] constexpr destructors run too late for temporaries created inside __builtin_constant_p
  2020-04-21  4:34 [Bug c++/94676] New: constexpr destructors run too late for temporaries created inside __builtin_constant_p richard-gccbugzilla at metafoo dot co.uk
@ 2020-04-21  7:24 ` redi at gcc dot gnu.org
  2020-04-21  7:44 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-21  7:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94676

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-04-21
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/94676] constexpr destructors run too late for temporaries created inside __builtin_constant_p
  2020-04-21  4:34 [Bug c++/94676] New: constexpr destructors run too late for temporaries created inside __builtin_constant_p richard-gccbugzilla at metafoo dot co.uk
  2020-04-21  7:24 ` [Bug c++/94676] " redi at gcc dot gnu.org
@ 2020-04-21  7:44 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-21  7:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94676

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org
            Version|unknown                     |10.0

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Jason, your thoughts about this?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-21  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21  4:34 [Bug c++/94676] New: constexpr destructors run too late for temporaries created inside __builtin_constant_p richard-gccbugzilla at metafoo dot co.uk
2020-04-21  7:24 ` [Bug c++/94676] " redi at gcc dot gnu.org
2020-04-21  7:44 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).