public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void*
@ 2023-06-21 16:16 mpolacek at gcc dot gnu.org
  2023-06-22  6:28 ` [Bug c++/110344] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-06-21 16:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110344
           Summary: [C++26] P2738R1 - constexpr cast from void*
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

See <https://wg21.link/P2738R1>.

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
@ 2023-06-22  6:28 ` pinskia at gcc dot gnu.org
  2023-06-24 21:55 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-22  6:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-22
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
  2023-06-22  6:28 ` [Bug c++/110344] " pinskia at gcc dot gnu.org
@ 2023-06-24 21:55 ` jason at gcc dot gnu.org
  2023-06-24 21:57 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-24 21:55 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Reduced version of the paper's testcase that we already (wrongly) accept:

class Doer {
private:
  const void *ob;
  int (*fn)(const void *);
public:
  template <typename T>
  constexpr Doer(const T &t)
    : ob{&t},
      fn{[](const void *p) { return static_cast<const T *>(p)->doit(); }}
  {}
  constexpr int operator()() const { return fn(ob); }
};
struct Thing { constexpr int doit() const { return 42; }; };
static_assert (Doer(Thing())() == 42);

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
  2023-06-22  6:28 ` [Bug c++/110344] " pinskia at gcc dot gnu.org
  2023-06-24 21:55 ` jason at gcc dot gnu.org
@ 2023-06-24 21:57 ` jason at gcc dot gnu.org
  2023-06-27 19:03 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-24 21:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Version of the paper testcase that just adds constexpr, that we currently
reject:

#include <string_view>
struct Sheep {
  constexpr std::string_view speak() const noexcept { return "Baaaaaa"; }
};
struct Cow {
  constexpr std::string_view speak() const noexcept { return "Mooo"; }
};
class Animal_View {
private:
  const void *animal;
  std::string_view (*speak_function)(const void *);
public:
  template <typename Animal>
  constexpr Animal_View(const Animal &a)
    : animal{&a}, speak_function{[](const void *object) {
                                   return static_cast<const Animal
*>(object)->speak();
                                 }} {}
  constexpr std::string_view speak() const noexcept {
    return speak_function(animal);
  }
};
// This is the key bit here. This is a single concrete function                 
// that can take anything that happens to have the "Animal_View"                
// interface                                                                    
constexpr std::string_view do_speak(Animal_View av) { return av.speak(); }
int main() {
  // A Cow is a cow. The only think that makes it special                       
  // is that it has a "std::string_view speak() const" member                   
  constexpr Cow cow;
  constexpr auto result = do_speak(cow);
  return static_cast<int>(result.size());
}

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-06-24 21:57 ` jason at gcc dot gnu.org
@ 2023-06-27 19:03 ` jason at gcc dot gnu.org
  2023-06-28  3:29 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-27 19:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-06-27 19:03 ` jason at gcc dot gnu.org
@ 2023-06-28  3:29 ` cvs-commit at gcc dot gnu.org
  2023-06-28  3:34 ` jason at gcc dot gnu.org
  2023-07-14 22:38 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-28  3:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:a1c6e9631ca33990a2b7411060ca4d18db081a7d

commit r14-2146-ga1c6e9631ca33990a2b7411060ca4d18db081a7d
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Jun 24 05:15:02 2023 -0400

    c++: C++26 constexpr cast from void* [PR110344]

    P2768 allows static_cast from void* to ob* in constant evaluation if the
    pointer does in fact point to an object of the appropriate type.
    cxx_fold_indirect_ref already does the work of finding such an object if it
    happens to be a subobject rather than the outermost object at that address,
    as in constexpr-voidptr2.C.

            P2768
            PR c++/110344

    gcc/c-family/ChangeLog:

            * c-cppbuiltin.cc (c_cpp_builtins): Update __cpp_constexpr.

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_constant_expression): In C++26, allow cast
            from void* to the type of a pointed-to object.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp26/constexpr-voidptr1.C: New test.
            * g++.dg/cpp26/constexpr-voidptr2.C: New test.
            * g++.dg/cpp26/feat-cxx26.C: New test.

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-06-28  3:29 ` cvs-commit at gcc dot gnu.org
@ 2023-06-28  3:34 ` jason at gcc dot gnu.org
  2023-07-14 22:38 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-28  3:34 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Implemented for GCC 14.

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

* [Bug c++/110344] [C++26] P2738R1 - constexpr cast from void*
  2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-06-28  3:34 ` jason at gcc dot gnu.org
@ 2023-07-14 22:38 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-14 22:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:8d344146727da02eb5c62fbf6cee97a4e96d63db

commit r14-2535-g8d344146727da02eb5c62fbf6cee97a4e96d63db
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 14 09:37:21 2023 -0400

    c++: c++26 regression fixes

    Apparently I wasn't actually running the testsuite in C++26 mode like I
    thought I was, so there were some failures I wasn't seeing.

    The constexpr hunk fixes regressions with the P2738 implementation; we
still
    need to use the old handling for casting from void pointers to heap
    variables.

            PR c++/110344

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_constant_expression): Move P2738 handling
            after heap handling.
            * name-lookup.cc (get_cxx_dialect_name): Add C++26.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-cast2.C: Adjust for P2738.
            * g++.dg/ipa/devirt-45.C: Handle -fimplicit-constexpr.

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

end of thread, other threads:[~2023-07-14 22:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21 16:16 [Bug c++/110344] New: [C++26] P2738R1 - constexpr cast from void* mpolacek at gcc dot gnu.org
2023-06-22  6:28 ` [Bug c++/110344] " pinskia at gcc dot gnu.org
2023-06-24 21:55 ` jason at gcc dot gnu.org
2023-06-24 21:57 ` jason at gcc dot gnu.org
2023-06-27 19:03 ` jason at gcc dot gnu.org
2023-06-28  3:29 ` cvs-commit at gcc dot gnu.org
2023-06-28  3:34 ` jason at gcc dot gnu.org
2023-07-14 22:38 ` cvs-commit 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).