public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102420] New: null pointer dereference constant
@ 2021-09-20 22:13 johelegp at gmail dot com
  2021-09-20 22:14 ` [Bug c++/102420] null pointer dereference during constant evaluation not rejected johelegp at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: johelegp at gmail dot com @ 2021-09-20 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102420
           Summary: null pointer dereference constant
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

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

* [Bug c++/102420] null pointer dereference during constant evaluation not rejected
  2021-09-20 22:13 [Bug c++/102420] New: null pointer dereference constant johelegp at gmail dot com
@ 2021-09-20 22:14 ` johelegp at gmail dot com
  2021-09-20 22:25 ` pinskia at gcc dot gnu.org
  2023-12-19 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: johelegp at gmail dot com @ 2021-09-20 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

Johel Ernesto Guerrero Peña <johelegp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|null pointer dereference    |null pointer dereference
                   |constant                    |during constant evaluation
                   |                            |not rejected
             Blocks|                            |55004

--- Comment #1 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
See https://godbolt.org/z/r5zxPTcK6.
```C++
struct X {
  constexpr void f() { }
};
int main() {
  []() consteval {
    X* x{nullptr};
    x->f();
  }();
}
```


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004
[Bug 55004] [meta-bug] constexpr issues

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

* [Bug c++/102420] null pointer dereference during constant evaluation not rejected
  2021-09-20 22:13 [Bug c++/102420] New: null pointer dereference constant johelegp at gmail dot com
  2021-09-20 22:14 ` [Bug c++/102420] null pointer dereference during constant evaluation not rejected johelegp at gmail dot com
@ 2021-09-20 22:25 ` pinskia at gcc dot gnu.org
  2023-12-19 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-20 22:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-09-20
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, here is a testcase which does not require C++20 (though it does use
a GNU extension):

struct X {
  constexpr int f() { return 0; }
};
constexpr int g() {
    return (X*){nullptr}->f();
}

int t = g();
---- CUT ----
here is one which is invalid C++14 (and does not use the GNU extension):
struct X {
  constexpr int f() { return 0; }
};
constexpr int g() {
    X *x = nullptr;
    return x->f();
}

int t = g();
-------- CUT ------
I only noticed that clang rejects it while ICC and MSVC accept it also.

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

* [Bug c++/102420] null pointer dereference during constant evaluation not rejected
  2021-09-20 22:13 [Bug c++/102420] New: null pointer dereference constant johelegp at gmail dot com
  2021-09-20 22:14 ` [Bug c++/102420] null pointer dereference during constant evaluation not rejected johelegp at gmail dot com
  2021-09-20 22:25 ` pinskia at gcc dot gnu.org
@ 2023-12-19 21:19 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-19 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

https://gcc.gnu.org/g:5ba949c096f5250aa4efb94fb7c94d1304c1bf39

commit r14-6722-g5ba949c096f5250aa4efb94fb7c94d1304c1bf39
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sun Dec 17 12:46:02 2023 +1100

    c++: Check null pointer deref when calling memfn in constexpr [PR102420]

    Calling a non-static member function on a null pointer is undefined
    behaviour (see [expr.ref] p8) and should error in constant evaluation,
    even if the 'this' pointer is never actually accessed within that
    function.

    One catch is that currently, the function pointer conversion operator
    for lambdas passes a null pointer as the 'this' pointer to the
    underlying 'operator()', so for now we ignore such calls.

            PR c++/102420

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_bind_parameters_in_call): Check for calling
            non-static member functions with a null pointer.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-memfn2.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

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

end of thread, other threads:[~2023-12-19 21:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 22:13 [Bug c++/102420] New: null pointer dereference constant johelegp at gmail dot com
2021-09-20 22:14 ` [Bug c++/102420] null pointer dereference during constant evaluation not rejected johelegp at gmail dot com
2021-09-20 22:25 ` pinskia at gcc dot gnu.org
2023-12-19 21:19 ` 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).