public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102623] New: Failure to detect destructed scalar objects in consteval function
@ 2021-10-05 19:41 gabravier at gmail dot com
  2021-10-05 19:55 ` [Bug c++/102623] " pinskia at gcc dot gnu.org
  2022-01-17 10:35 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gabravier at gmail dot com @ 2021-10-05 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102623
           Summary: Failure to detect destructed scalar objects in
                    consteval function
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

using T = int;
consteval bool f()
{
  T t = 42;
  t.~T();
  return (t == 42);
}

bool x = f();

This code should not compile, as `f` invokes undefined behavior during constant
evaluation, as Clang diagnoses:

<source>:9:10: error: call to consteval function 'f' is not a constant
expression
bool x = f();
         ^
<source>:6:11: note: read of object outside its lifetime is not allowed in a
constant expression
  return (t == 42);
          ^

The specific usage with `int` here was not UB until C++20 (although
pseudo-destructors weren't allowed in constant expressions until C++20 anyway),
but as of
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0593r6.html#pseudo-destructor-calls
pseudo-destructors end the lifetime of the operand.

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

* [Bug c++/102623] Failure to detect destructed scalar objects in consteval function
  2021-10-05 19:41 [Bug c++/102623] New: Failure to detect destructed scalar objects in consteval function gabravier at gmail dot com
@ 2021-10-05 19:55 ` pinskia at gcc dot gnu.org
  2022-01-17 10:35 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 19:55 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=71093

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect this is basically PR 71093.

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

* [Bug c++/102623] Failure to detect destructed scalar objects in consteval function
  2021-10-05 19:41 [Bug c++/102623] New: Failure to detect destructed scalar objects in consteval function gabravier at gmail dot com
  2021-10-05 19:55 ` [Bug c++/102623] " pinskia at gcc dot gnu.org
@ 2022-01-17 10:35 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-17 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-01-17

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. I thought I saw another issue related to this one where the variable
goes out of scope instead.

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

end of thread, other threads:[~2022-01-17 10:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 19:41 [Bug c++/102623] New: Failure to detect destructed scalar objects in consteval function gabravier at gmail dot com
2021-10-05 19:55 ` [Bug c++/102623] " pinskia at gcc dot gnu.org
2022-01-17 10:35 ` pinskia 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).