public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111122] New: local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation
@ 2023-08-23 19:50 jakub at gcc dot gnu.org
  2023-08-23 19:56 ` [Bug c++/111122] " pinskia at gcc dot gnu.org
  2023-08-23 20:01 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-23 19:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111122
           Summary: local temps from get_nsdmi -> break_out_target_exprs
                    break constexpr evaluation
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

struct T {
  const char *d = new char[2] { 'o', 'k' };
  constexpr int size () const { return 2; }
  constexpr const char *data () const { return d; }
  constexpr ~T () { delete[] d; }
};
constexpr int a = T{}.size ();
constexpr int b = T{}.data ()[0];
//constexpr const char *c = T{}.data ();

is rejected by g++ with
test42.C:7:29: error: the value of ‘<anonymous>’ is not usable in a constant
expression
    7 | constexpr int a = T{}.size ();
      |                             ^
test42.C:7:21: note: ‘<anonymous>’ was not declared ‘constexpr’
    7 | constexpr int a = T{}.size ();
      |                     ^
test42.C:8:32: error: the value of ‘<anonymous>’ is not usable in a constant
expression
    8 | constexpr int b = T{}.data ()[0];
      |                                ^
test42.C:8:21: note: ‘<anonymous>’ was not declared ‘constexpr’
    8 | constexpr int b = T{}.data ()[0];
      |                     ^
during potential_constant_expression_1,
while clang++ accepts it.

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

* [Bug c++/111122] local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation
  2023-08-23 19:50 [Bug c++/111122] New: local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation jakub at gcc dot gnu.org
@ 2023-08-23 19:56 ` pinskia at gcc dot gnu.org
  2023-08-23 20:01 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-23 19:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Try from inside a function instead. There is another bug about local Temps used
from constexpr from a non-function scope causinbissues.

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

* [Bug c++/111122] local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation
  2023-08-23 19:50 [Bug c++/111122] New: local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation jakub at gcc dot gnu.org
  2023-08-23 19:56 ` [Bug c++/111122] " pinskia at gcc dot gnu.org
@ 2023-08-23 20:01 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-08-23 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Sure,

struct T {
  const char *d = init ();
  constexpr int size () const { return 2; }
  constexpr const char *data () const { return d; }
  constexpr const char *init () const { return new char[2] { 'o', 'k' }; }
  constexpr ~T () { delete[] d; }
};
constexpr int a = T{}.size ();
constexpr int b = T{}.data ()[0];

works.

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

end of thread, other threads:[~2023-08-23 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23 19:50 [Bug c++/111122] New: local temps from get_nsdmi -> break_out_target_exprs break constexpr evaluation jakub at gcc dot gnu.org
2023-08-23 19:56 ` [Bug c++/111122] " pinskia at gcc dot gnu.org
2023-08-23 20:01 ` 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).