chromium/tools/clang/raw_ptr_plugin/tests/bad_raw_ptr_cast_recursive.cpp

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/raw_ptr.h"

struct A;
struct B;
struct C;
struct D;

// raw_ptr<int> <-- A <-> B --> C
//                        ^
//                        |
//                        D
// A, B and D are casting-unsafe.
struct A {
  B* b;
  raw_ptr<int> ptr;
};

struct B {
  A* a;
  C* c;
};

struct C {};

struct D {
  B* b;
};

void CastToCastingUnsafe() {
  void* p = nullptr;

  (void)static_cast<A*>(p);  // Error.
  (void)static_cast<B*>(p);  // Error.
  (void)static_cast<C*>(p);  // OK.
  (void)static_cast<D*>(p);  // Error.
}