public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113047] New: dereferencing a null pointer in a constant expression
@ 2023-12-16 21:01 gcc_bz at brnz dot org
  2023-12-16 21:02 ` [Bug c++/113047] " gcc_bz at brnz dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc_bz at brnz dot org @ 2023-12-16 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113047
           Summary: dereferencing a null pointer in a constant expression
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc_bz at brnz dot org
  Target Milestone: ---

Should it be possible to dereference a null pointer in a C++20 constant
expression?

Consider this c++20 code:

struct T {
  constexpr bool isNull() {
    return !this;
  }
};
static_assert(((T*)nullptr)->isNull());

constexpr T* t = nullptr;
static_assert((*t).isNull());


I would expect this to not compile due to the dereferencing of a null pointer
in a constant expression.

With reference to https://godbolt.org/z/q53rz5d69

By default, gcc-13.2 compiles without warning. -Wall yields a -Wnonnull
warning.

clang-17.0.1 produces errors and warning, by default.

msvc 19.38 compiles without warning.

Potentially relevant context:
2748. Accessing static data members via null pointer
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2748

2823. Implicit undefined behavior when dereferencing pointers
https://cplusplus.github.io/CWG/issues/2823.html

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

end of thread, other threads:[~2024-01-18 19:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-16 21:01 [Bug c++/113047] New: dereferencing a null pointer in a constant expression gcc_bz at brnz dot org
2023-12-16 21:02 ` [Bug c++/113047] " gcc_bz at brnz dot org
2023-12-16 21:16 ` pinskia at gcc dot gnu.org
2023-12-19  4:22 ` de34 at live dot cn
2023-12-19 22:31 ` nathanieloshead at gmail dot com
2024-01-18 19:17 ` mpolacek 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).