public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96414] New: Second char relation test incorrect with constexpr dynamic allocation
@ 2020-08-02  0:13 pkeir at outlook dot com
  2020-08-02  0:15 ` [Bug c++/96414] " pkeir at outlook dot com
  2021-04-19  1:53 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: pkeir at outlook dot com @ 2020-08-02  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96414
           Summary: Second char relation test incorrect with constexpr
                    dynamic allocation
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pkeir at outlook dot com
  Target Milestone: ---

Created attachment 48981
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48981&action=edit
The file containing the code described.

The attached C++20 code behaves differently at compile-time than at runtime,
but shouldn't. As with `__gnu_cxx::char_traits<char>::lt`, the function
`lt_fun` applies built-in `operator<` to two character references, and returns
the result as an `int`. However, with the character pointer `pc` pointing to
memory allocated dynamically, the second call returns true (1) indicating that
'a' < 'a' is true. This is demonstrated by a failing static assert. Commenting
out the static assert produces an executable which correctly reports that 'a' <
'a' is false; by returning a 0.

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

* [Bug c++/96414] Second char relation test incorrect with constexpr dynamic allocation
  2020-08-02  0:13 [Bug c++/96414] New: Second char relation test incorrect with constexpr dynamic allocation pkeir at outlook dot com
@ 2020-08-02  0:15 ` pkeir at outlook dot com
  2021-04-19  1:53 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pkeir at outlook dot com @ 2020-08-02  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Paul Keir <pkeir at outlook dot com> ---
constexpr int lt_fun(const char& c1, const char& c2) {
  return c1 < c2;
}

constexpr bool doit()
{
  char *pc = new char;
  const char* s = "a";

  *pc = 'b';
            lt_fun(*s, *pc); // a < b

  *pc = 'a';
  bool lt = lt_fun(*s, *pc); // a < a

  delete pc;

  return !lt;
}

int main(int argc, char *argv[])
{
  static_assert(doit());
  return doit() ? 0 : -1;
}

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

* [Bug c++/96414] Second char relation test incorrect with constexpr dynamic allocation
  2020-08-02  0:13 [Bug c++/96414] New: Second char relation test incorrect with constexpr dynamic allocation pkeir at outlook dot com
  2020-08-02  0:15 ` [Bug c++/96414] " pkeir at outlook dot com
@ 2021-04-19  1:53 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-19  1:53 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the bug report.  I think the underlying bug here is the same as that
of the recently fixed PR99859, and indeed trunk accepts your testcase ever
since r11-8056, so I'm going to mark this PR as a duplicate.

*** This bug has been marked as a duplicate of bug 99859 ***

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

end of thread, other threads:[~2021-04-19  1:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-02  0:13 [Bug c++/96414] New: Second char relation test incorrect with constexpr dynamic allocation pkeir at outlook dot com
2020-08-02  0:15 ` [Bug c++/96414] " pkeir at outlook dot com
2021-04-19  1:53 ` ppalka 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).