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

            Bug ID: 96003
           Summary: Maybe a false positive for -Werror=nonnull
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: msebor at gcc dot gnu.org
  Target Milestone: ---

It's reduced from inkscape project. Happens since r11-1697-g75ff24e1920ea6b1:

$ cat /tmp/folis.ii
class Managed {};
class Anchored {
public:
  void release();
  Managed _anchor;
};
template <typename R> void release(R r) {
  static_cast<Anchored *>(r)->release();
}
class Selection : Managed, public Anchored {};
class AppSelectionModel {
  AppSelectionModel() { release(new Selection); }
};

$ g++ /tmp/folis.ii -Werror=nonnull
/tmp/folis.ii: In instantiation of ‘void release(R) [with R = Selection*]’:
/tmp/folis.ii:12:46:   required from here
/tmp/folis.ii:8:38: error: ‘this’ pointer null [-Werror=nonnull]
    8 |   static_cast<Anchored *>(r)->release();
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/tmp/folis.ii:4:8: note: in a call to non-static member function ‘void
Anchored::release()’
    4 |   void release();
      |        ^~~~~~~
cc1plus: some warnings being treated as errors

Reply via email to