From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../tools/clang/plugins/tests/base_refcounted.cpp | 72 ++++++++++++ .../tools/clang/plugins/tests/base_refcounted.h | 121 +++++++++++++++++++++ .../tools/clang/plugins/tests/base_refcounted.txt | 23 ++++ .../tools/clang/plugins/tests/inline_copy_ctor.cpp | 5 + .../tools/clang/plugins/tests/inline_copy_ctor.h | 12 ++ .../tools/clang/plugins/tests/inline_copy_ctor.txt | 5 + .../tools/clang/plugins/tests/inline_ctor.cpp | 25 +++++ .../trunk/tools/clang/plugins/tests/inline_ctor.h | 21 ++++ .../tools/clang/plugins/tests/inline_ctor.txt | 8 ++ .../tools/clang/plugins/tests/missing_ctor.cpp | 23 ++++ .../trunk/tools/clang/plugins/tests/missing_ctor.h | 19 ++++ .../tools/clang/plugins/tests/missing_ctor.txt | 6 + .../plugins/tests/nested_class_inline_ctor.cpp | 5 + .../clang/plugins/tests/nested_class_inline_ctor.h | 22 ++++ .../plugins/tests/nested_class_inline_ctor.txt | 8 ++ .../clang/plugins/tests/overridden_methods.cpp | 38 +++++++ .../tools/clang/plugins/tests/overridden_methods.h | 54 +++++++++ .../clang/plugins/tests/overridden_methods.txt | 20 ++++ .../webrtc/trunk/tools/clang/plugins/tests/test.sh | 72 ++++++++++++ .../tools/clang/plugins/tests/virtual_methods.cpp | 36 ++++++ .../tools/clang/plugins/tests/virtual_methods.h | 39 +++++++ .../tools/clang/plugins/tests/virtual_methods.txt | 8 ++ 22 files changed, 642 insertions(+) create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.txt create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.txt create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.txt create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.txt create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.txt create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.txt create mode 100755 media/webrtc/trunk/tools/clang/plugins/tests/test.sh create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.cpp create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.h create mode 100644 media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.txt (limited to 'media/webrtc/trunk/tools/clang/plugins/tests') diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.cpp new file mode 100644 index 000000000..364a3e888 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base_refcounted.h" + +#include + +namespace { + +// Unsafe; should error. +class AnonymousDerivedProtectedToPublicInImpl + : public ProtectedRefCountedDtorInHeader { + public: + AnonymousDerivedProtectedToPublicInImpl() {} + ~AnonymousDerivedProtectedToPublicInImpl() {} +}; + +} // namespace + +// Unsafe; should error. +class PublicRefCountedDtorInImpl + : public base::RefCounted { + public: + PublicRefCountedDtorInImpl() {} + ~PublicRefCountedDtorInImpl() {} + + private: + friend class base::RefCounted; +}; + +class Foo { + public: + class BarInterface { + protected: + virtual ~BarInterface() {} + }; + + typedef base::RefCounted RefCountedBar; + typedef RefCountedBar AnotherTypedef; +}; + +class Baz { + public: + typedef typename Foo::AnotherTypedef MyLocalTypedef; +}; + +// Unsafe; should error. +class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef { + public: + UnsafeTypedefChainInImpl() {} + ~UnsafeTypedefChainInImpl() {} +}; + +int main() { + PublicRefCountedDtorInHeader bad; + PublicRefCountedDtorInImpl also_bad; + + ProtectedRefCountedDtorInHeader* protected_ok = NULL; + PrivateRefCountedDtorInHeader* private_ok = NULL; + + DerivedProtectedToPublicInHeader still_bad; + PublicRefCountedThreadSafeDtorInHeader another_bad_variation; + AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too; + ImplicitDerivedProtectedToPublicInHeader bad_yet_again; + UnsafeTypedefChainInImpl and_again_this_is_bad; + + WebKitPublicDtorInHeader ignored; + WebKitDerivedPublicDtorInHeader still_ignored; + + return 0; +} diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.h b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.h new file mode 100644 index 000000000..1e5321599 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.h @@ -0,0 +1,121 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_REFCOUNTED_H_ +#define BASE_REFCOUNTED_H_ + +namespace base { + +template +class RefCounted { + public: + RefCounted() {} + ~RefCounted() {} +}; + +template +class RefCountedThreadSafe { + public: + RefCountedThreadSafe() {} + ~RefCountedThreadSafe() {} +}; + +} // namespace base + +// Ignore classes whose inheritance tree ends in WebKit's RefCounted base +// class. Though prone to error, this pattern is very prevalent in WebKit +// code, so do not issue any warnings. +namespace WebKit { + +template +class RefCounted { + public: + RefCounted() {} + ~RefCounted() {} +}; + +} // namespace WebKit + +// Unsafe; should error. +class PublicRefCountedDtorInHeader + : public base::RefCounted { + public: + PublicRefCountedDtorInHeader() {} + ~PublicRefCountedDtorInHeader() {} + + private: + friend class base::RefCounted; +}; + +// Unsafe; should error. +class PublicRefCountedThreadSafeDtorInHeader + : public base::RefCountedThreadSafe< + PublicRefCountedThreadSafeDtorInHeader> { + public: + PublicRefCountedThreadSafeDtorInHeader() {} + ~PublicRefCountedThreadSafeDtorInHeader() {} + + private: + friend class base::RefCountedThreadSafe< + PublicRefCountedThreadSafeDtorInHeader>; +}; + +// Safe; should not have errors. +class ProtectedRefCountedDtorInHeader + : public base::RefCounted { + public: + ProtectedRefCountedDtorInHeader() {} + + protected: + ~ProtectedRefCountedDtorInHeader() {} + + private: + friend class base::RefCounted; +}; + +// Safe; should not have errors. +class PrivateRefCountedDtorInHeader + : public base::RefCounted { + public: + PrivateRefCountedDtorInHeader() {} + + private: + ~PrivateRefCountedDtorInHeader() {} + friend class base::RefCounted; +}; + +// Unsafe; A grandchild class ends up exposing their parent and grandparent's +// destructors. +class DerivedProtectedToPublicInHeader + : public ProtectedRefCountedDtorInHeader { + public: + DerivedProtectedToPublicInHeader() {} + ~DerivedProtectedToPublicInHeader() {} +}; + +// Unsafe; A grandchild ends up implicitly exposing their parent and +// grantparent's destructors. +class ImplicitDerivedProtectedToPublicInHeader + : public ProtectedRefCountedDtorInHeader { + public: + ImplicitDerivedProtectedToPublicInHeader() {} +}; + +// Unsafe-but-ignored; should not have errors. +class WebKitPublicDtorInHeader + : public WebKit::RefCounted { + public: + WebKitPublicDtorInHeader() {} + ~WebKitPublicDtorInHeader() {} +}; + +// Unsafe-but-ignored; should not have errors. +class WebKitDerivedPublicDtorInHeader + : public WebKitPublicDtorInHeader { + public: + WebKitDerivedPublicDtorInHeader() {} + ~WebKitDerivedPublicDtorInHeader() {} +}; + +#endif // BASE_REFCOUNTED_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.txt b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.txt new file mode 100644 index 000000000..462642417 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.txt @@ -0,0 +1,23 @@ +In file included from base_refcounted.cpp:5: +./base_refcounted.h:45:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~PublicRefCountedDtorInHeader() {} + ^ +./base_refcounted.h:57:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~PublicRefCountedThreadSafeDtorInHeader() {} + ^ +./base_refcounted.h:94:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~DerivedProtectedToPublicInHeader() {} + ^ +./base_refcounted.h:99:1: warning: [chromium-style] Classes that are ref-counted should have explicit destructors that are protected or private. +class ImplicitDerivedProtectedToPublicInHeader +^ +base_refcounted.cpp:16:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~AnonymousDerivedProtectedToPublicInImpl() {} + ^ +base_refcounted.cpp:26:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~PublicRefCountedDtorInImpl() {} + ^ +base_refcounted.cpp:52:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. + ~UnsafeTypedefChainInImpl() {} + ^ +7 warnings generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.cpp new file mode 100644 index 000000000..dcd90020c --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.cpp @@ -0,0 +1,5 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "inline_copy_ctor.h" diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.h b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.h new file mode 100644 index 000000000..619a18392 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.h @@ -0,0 +1,12 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +struct C { + C(); + ~C(); + + static C foo() { return C(); } + + int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p , q, r, s, t, u, v, w, x; +}; diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.txt b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.txt new file mode 100644 index 000000000..bc4bd8911 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_copy_ctor.txt @@ -0,0 +1,5 @@ +In file included from inline_copy_ctor.cpp:5: +./inline_copy_ctor.h:5:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line copy constructor. +struct C { +^ +1 warning generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.cpp new file mode 100644 index 000000000..6a751fb40 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "inline_ctor.h" + +#include +#include + +// We don't warn on classes that are in CPP files. +class InlineInCPPOK { + public: + InlineInCPPOK() {} + ~InlineInCPPOK() {} + + private: + std::vector one_; + std::vector two_; +}; + +int main() { + InlineInCPPOK one; + InlineCtorsArentOKInHeader two; + return 0; +} diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.h b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.h new file mode 100644 index 000000000..d053b2f57 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.h @@ -0,0 +1,21 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef INLINE_CTOR_H_ +#define INLINE_CTOR_H_ + +#include +#include + +class InlineCtorsArentOKInHeader { + public: + InlineCtorsArentOKInHeader() {} + ~InlineCtorsArentOKInHeader() {} + + private: + std::vector one_; + std::vector two_; +}; + +#endif // INLINE_CTOR_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.txt b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.txt new file mode 100644 index 000000000..caa0cb4e3 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/inline_ctor.txt @@ -0,0 +1,8 @@ +In file included from inline_ctor.cpp:5: +./inline_ctor.h:13:3: warning: [chromium-style] Complex constructor has an inlined body. + InlineCtorsArentOKInHeader() {} + ^ +./inline_ctor.h:14:3: warning: [chromium-style] Complex destructor has an inline body. + ~InlineCtorsArentOKInHeader() {} + ^ +2 warnings generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.cpp new file mode 100644 index 000000000..8ee2fb2ac --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "missing_ctor.h" + +#include +#include + +// We don't warn on classes that use default ctors in cpp files. +class MissingInCPPOK { + public: + + private: + std::vector one_; + std::vector two_; +}; + +int main() { + MissingInCPPOK one; + MissingCtorsArentOKInHeader two; + return 0; +} diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.h b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.h new file mode 100644 index 000000000..1050457a1 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.h @@ -0,0 +1,19 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MISSING_CTOR_H_ +#define MISSING_CTOR_H_ + +#include +#include + +class MissingCtorsArentOKInHeader { + public: + + private: + std::vector one_; + std::vector two_; +}; + +#endif // MISSING_CTOR_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.txt b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.txt new file mode 100644 index 000000000..301449c4a --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/missing_ctor.txt @@ -0,0 +1,6 @@ +In file included from missing_ctor.cpp:5: +./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line constructor. +class MissingCtorsArentOKInHeader { +^ +./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line destructor. +2 warnings generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.cpp new file mode 100644 index 000000000..aa90a95eb --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.cpp @@ -0,0 +1,5 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "nested_class_inline_ctor.h" diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.h b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.h new file mode 100644 index 000000000..01cfea923 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NESTED_CLASS_INLINE_CTOR_H_ +#define NESTED_CLASS_INLINE_CTOR_H_ + +#include +#include + +// See crbug.com/136863. + +class Foo { + class Bar { + Bar() {} + ~Bar() {} + + std::vector a; + }; +}; + +#endif // NESTED_CLASS_INLINE_CTOR_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.txt b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.txt new file mode 100644 index 000000000..39bd6e1dc --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/nested_class_inline_ctor.txt @@ -0,0 +1,8 @@ +In file included from nested_class_inline_ctor.cpp:5: +./nested_class_inline_ctor.h:15:5: warning: [chromium-style] Complex constructor has an inlined body. + Bar() {} + ^ +./nested_class_inline_ctor.h:16:5: warning: [chromium-style] Complex destructor has an inline body. + ~Bar() {} + ^ +2 warnings generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.cpp new file mode 100644 index 000000000..f572a4173 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "overridden_methods.h" + +// Fill in the implementations +void DerivedClass::SomeMethod() {} +void DerivedClass::SomeOtherMethod() {} +void DerivedClass::WebKitModifiedSomething() {} + +class ImplementationInterimClass : public BaseClass { + public: + // Should not warn about pure virtual methods. + virtual void SomeMethod() = 0; +}; + +class ImplementationDerivedClass : public ImplementationInterimClass, + public webkit_glue::WebKitObserverImpl { + public: + // Should not warn about destructors. + virtual ~ImplementationDerivedClass() {} + // Should warn. + virtual void SomeMethod(); + // Should not warn if marked as override. + virtual void SomeOtherMethod() override; + // Should not warn for inline implementations in implementation files. + virtual void SomeInlineMethod() {} + // Should not warn if overriding a method whose origin is WebKit. + virtual void WebKitModifiedSomething(); + // Should warn if overridden method isn't pure. + virtual void SomeNonPureBaseMethod() {} +}; + +int main() { + DerivedClass something; + ImplementationDerivedClass something_else; +} diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.h b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.h new file mode 100644 index 000000000..150c79913 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.h @@ -0,0 +1,54 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef OVERRIDDEN_METHODS_H_ +#define OVERRIDDEN_METHODS_H_ + +// Should warn about overriding of methods. +class BaseClass { + public: + virtual ~BaseClass() {} + virtual void SomeMethod() = 0; + virtual void SomeOtherMethod() = 0; + virtual void SomeInlineMethod() = 0; + virtual void SomeNonPureBaseMethod() {} +}; + +class InterimClass : public BaseClass { + // Should not warn about pure virtual methods. + virtual void SomeMethod() = 0; +}; + +namespace WebKit { +class WebKitObserver { + public: + virtual void WebKitModifiedSomething() {}; +}; +} // namespace WebKit + +namespace webkit_glue { +class WebKitObserverImpl : WebKit::WebKitObserver { + public: + virtual void WebKitModifiedSomething() {}; +}; +} // namespace webkit_glue + +class DerivedClass : public InterimClass, + public webkit_glue::WebKitObserverImpl { + public: + // Should not warn about destructors. + virtual ~DerivedClass() {} + // Should warn. + virtual void SomeMethod(); + // Should not warn if marked as override. + virtual void SomeOtherMethod() override; + // Should warn for inline implementations. + virtual void SomeInlineMethod() {} + // Should not warn if overriding a method whose origin is WebKit. + virtual void WebKitModifiedSomething(); + // Should warn if overridden method isn't pure. + virtual void SomeNonPureBaseMethod() {} +}; + +#endif // OVERRIDDEN_METHODS_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.txt b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.txt new file mode 100644 index 000000000..7553ade70 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/overridden_methods.txt @@ -0,0 +1,20 @@ +In file included from overridden_methods.cpp:5: +./overridden_methods.h:43:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeMethod(); + ^ +./overridden_methods.h:47:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeInlineMethod() {} + ^ +./overridden_methods.h:51:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeNonPureBaseMethod() {} + ^ +overridden_methods.cpp:24:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeMethod(); + ^ +overridden_methods.cpp:28:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeInlineMethod() {} + ^ +overridden_methods.cpp:32:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. + virtual void SomeNonPureBaseMethod() {} + ^ +6 warnings generated. diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/test.sh b/media/webrtc/trunk/tools/clang/plugins/tests/test.sh new file mode 100755 index 000000000..262ebbba2 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/test.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Hacky, primitive testing: This runs the style plugin for a set of input files +# and compares the output with golden result files. + +E_BADARGS=65 +E_FAILEDTEST=1 + +failed_any_test= + +# Prints usage information. +usage() { + echo "Usage: $(basename "${0}")" \ + "" + echo "" + echo " Runs all the libFindBadConstructs unit tests" + echo "" +} + +# Runs a single test case. +do_testcase() { + local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ + -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ + -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)" + local diffout="$(echo "${output}" | diff - "${2}")" + if [ "${diffout}" = "" ]; then + echo "PASS: ${1}" + else + failed_any_test=yes + echo "FAIL: ${1}" + echo "Output of compiler:" + echo "${output}" + echo "Expected output:" + cat "${2}" + echo + fi +} + +# Validate input to the script. +if [[ -z "${1}" ]]; then + usage + exit ${E_BADARGS} +elif [[ ! -d "${1}" ]]; then + echo "${1} is not a directory." + usage + exit ${E_BADARGS} +else + export CLANG_DIR="${PWD}/${1}" + echo "Using clang directory ${CLANG_DIR}..." + + # The golden files assume that the cwd is this directory. To make the script + # work no matter what the cwd is, explicitly cd to there. + cd "$(dirname "${0}")" + + if [ "$(uname -s)" = "Linux" ]; then + export LIB=so + elif [ "$(uname -s)" = "Darwin" ]; then + export LIB=dylib + fi +fi + +for input in *.cpp; do + do_testcase "${input}" "${input%cpp}txt" +done + +if [[ "${failed_any_test}" ]]; then + exit ${E_FAILEDTEST} +fi diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.cpp b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.cpp new file mode 100644 index 000000000..a07cbe487 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "virtual_methods.h" + +// Shouldn't warn about method usage in the implementation file. +class VirtualMethodsInImplementation { + public: + virtual void MethodIsAbstract() = 0; + virtual void MethodHasNoArguments(); + virtual void MethodHasEmptyDefaultImpl() {} + virtual bool ComplainAboutThis() { return true; } +}; + +// Stubs to fill in the abstract method +class ConcreteVirtualMethodsInHeaders : public VirtualMethodsInHeaders { + public: + virtual void MethodIsAbstract() override {} +}; + +class ConcreteVirtualMethodsInImplementation + : public VirtualMethodsInImplementation { + public: + virtual void MethodIsAbstract() override {} +}; + +// Fill in the implementations +void VirtualMethodsInHeaders::MethodHasNoArguments() {} +void WarnOnMissingVirtual::MethodHasNoArguments() {} +void VirtualMethodsInImplementation::MethodHasNoArguments() {} + +int main() { + ConcreteVirtualMethodsInHeaders one; + ConcreteVirtualMethodsInImplementation two; +} diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.h b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.h new file mode 100644 index 000000000..d9fbf96ed --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.h @@ -0,0 +1,39 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIRTUAL_METHODS_H_ +#define VIRTUAL_METHODS_H_ + +// Should warn about virtual method usage. +class VirtualMethodsInHeaders { + public: + // Don't complain about these. + virtual void MethodIsAbstract() = 0; + virtual void MethodHasNoArguments(); + virtual void MethodHasEmptyDefaultImpl() {} + + // But complain about this: + virtual bool ComplainAboutThis() { return true; } +}; + +// Complain on missing 'virtual' keyword in overrides. +class WarnOnMissingVirtual : public VirtualMethodsInHeaders { + public: + void MethodHasNoArguments() override; +}; + +// Don't complain about things in a 'testing' namespace. +namespace testing { +struct TestStruct {}; +} // namespace testing + +class VirtualMethodsInHeadersTesting : public VirtualMethodsInHeaders { + public: + // Don't complain about no virtual testing methods. + void MethodHasNoArguments(); + private: + testing::TestStruct tester_; +}; + +#endif // VIRTUAL_METHODS_H_ diff --git a/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.txt b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.txt new file mode 100644 index 000000000..571d6d667 --- /dev/null +++ b/media/webrtc/trunk/tools/clang/plugins/tests/virtual_methods.txt @@ -0,0 +1,8 @@ +In file included from virtual_methods.cpp:5: +./virtual_methods.h:17:36: warning: [chromium-style] virtual methods with non-empty bodies shouldn't be declared inline. + virtual bool ComplainAboutThis() { return true; } + ^ +./virtual_methods.h:23:3: warning: [chromium-style] Overriding method must have "virtual" keyword. + void MethodHasNoArguments() override; + ^ +2 warnings generated. -- cgit v1.2.3