brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 6d96c14 Raw
45 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s2// expected-no-diagnostics3 4#include "mock-types.h"5 6template <typename T> struct RefAllowingPartiallyDestroyed {7  T *t;8 9  RefAllowingPartiallyDestroyed() : t{} {};10  RefAllowingPartiallyDestroyed(T &) {}11  T *get() { return t; }12  T *ptr() { return t; }13  T *operator->() { return t; }14  operator const T &() const { return *t; }15  operator T &() { return *t; }16};17 18template <typename T> struct RefPtrAllowingPartiallyDestroyed {19  T *t;20 21  RefPtrAllowingPartiallyDestroyed() : t(new T) {}22  RefPtrAllowingPartiallyDestroyed(T *t) : t(t) {}23  T *get() { return t; }24  T *operator->() { return t; }25  const T *operator->() const { return t; }26  T &operator*() { return *t; }27  RefPtrAllowingPartiallyDestroyed &operator=(T *) { return *this; }28  operator bool() { return t; }29};30 31class RefCounted {32public:33  void ref() const;34  void deref() const;35  void someFunction();36};37 38RefAllowingPartiallyDestroyed<RefCounted> object1();39RefPtrAllowingPartiallyDestroyed<RefCounted> object2();40 41void testFunction() {42  object1()->someFunction();43  object2()->someFunction();44}45