[Bug c++/97230] Invocation of non-static member function on a null instance in core constant expression should not be allowed

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Sep 28 15:29:14 GMT 2020


Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-09-28
     Ever confirmed|0                           |1
           Keywords|compile-time-hog            |accepts-invalid

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC trunk does warn about exactly the issue:

ce.cc: In function 'int main()':
ce.cc:10:43: warning: 'this' pointer null [-Wnonnull]
   10 |     constexpr auto x = ((X*)nullptr)->foo();
      |                                           ^
ce.cc:4:19: note: in a call to non-static member function 'constexpr int
X::foo() const'
    4 |     constexpr int foo(){
      |                   ^~~

But that should be an error during constant evaluation.

More information about the Gcc-bugs mailing list