diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/tools/clang/plugins/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/tools/clang/plugins/tests')
22 files changed, 642 insertions, 0 deletions
diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.cpp new file mode 100644 index 0000000000..364a3e888c --- /dev/null +++ b/third_party/libwebrtc/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 <cstddef> + +namespace { + +// Unsafe; should error. +class AnonymousDerivedProtectedToPublicInImpl + : public ProtectedRefCountedDtorInHeader { + public: + AnonymousDerivedProtectedToPublicInImpl() {} + ~AnonymousDerivedProtectedToPublicInImpl() {} +}; + +} // namespace + +// Unsafe; should error. +class PublicRefCountedDtorInImpl + : public base::RefCounted<PublicRefCountedDtorInImpl> { + public: + PublicRefCountedDtorInImpl() {} + ~PublicRefCountedDtorInImpl() {} + + private: + friend class base::RefCounted<PublicRefCountedDtorInImpl>; +}; + +class Foo { + public: + class BarInterface { + protected: + virtual ~BarInterface() {} + }; + + typedef base::RefCounted<BarInterface> 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/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.h b/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.h new file mode 100644 index 0000000000..1e53215997 --- /dev/null +++ b/third_party/libwebrtc/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 <typename T> +class RefCounted { + public: + RefCounted() {} + ~RefCounted() {} +}; + +template <typename T> +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 <typename T> +class RefCounted { + public: + RefCounted() {} + ~RefCounted() {} +}; + +} // namespace WebKit + +// Unsafe; should error. +class PublicRefCountedDtorInHeader + : public base::RefCounted<PublicRefCountedDtorInHeader> { + public: + PublicRefCountedDtorInHeader() {} + ~PublicRefCountedDtorInHeader() {} + + private: + friend class base::RefCounted<PublicRefCountedDtorInHeader>; +}; + +// 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<ProtectedRefCountedDtorInHeader> { + public: + ProtectedRefCountedDtorInHeader() {} + + protected: + ~ProtectedRefCountedDtorInHeader() {} + + private: + friend class base::RefCounted<ProtectedRefCountedDtorInHeader>; +}; + +// Safe; should not have errors. +class PrivateRefCountedDtorInHeader + : public base::RefCounted<PrivateRefCountedDtorInHeader> { + public: + PrivateRefCountedDtorInHeader() {} + + private: + ~PrivateRefCountedDtorInHeader() {} + friend class base::RefCounted<PrivateRefCountedDtorInHeader>; +}; + +// 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<WebKitPublicDtorInHeader> { + public: + WebKitPublicDtorInHeader() {} + ~WebKitPublicDtorInHeader() {} +}; + +// Unsafe-but-ignored; should not have errors. +class WebKitDerivedPublicDtorInHeader + : public WebKitPublicDtorInHeader { + public: + WebKitDerivedPublicDtorInHeader() {} + ~WebKitDerivedPublicDtorInHeader() {} +}; + +#endif // BASE_REFCOUNTED_H_ diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.txt b/third_party/libwebrtc/tools/clang/plugins/tests/base_refcounted.txt new file mode 100644 index 0000000000..4626424177 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.cpp new file mode 100644 index 0000000000..dcd90020c5 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.h b/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.h new file mode 100644 index 0000000000..619a18392b --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.txt b/third_party/libwebrtc/tools/clang/plugins/tests/inline_copy_ctor.txt new file mode 100644 index 0000000000..bc4bd8911e --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.cpp new file mode 100644 index 0000000000..6a751fb405 --- /dev/null +++ b/third_party/libwebrtc/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 <string> +#include <vector> + +// We don't warn on classes that are in CPP files. +class InlineInCPPOK { + public: + InlineInCPPOK() {} + ~InlineInCPPOK() {} + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +int main() { + InlineInCPPOK one; + InlineCtorsArentOKInHeader two; + return 0; +} diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.h b/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.h new file mode 100644 index 0000000000..d053b2f57d --- /dev/null +++ b/third_party/libwebrtc/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 <string> +#include <vector> + +class InlineCtorsArentOKInHeader { + public: + InlineCtorsArentOKInHeader() {} + ~InlineCtorsArentOKInHeader() {} + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +#endif // INLINE_CTOR_H_ diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.txt b/third_party/libwebrtc/tools/clang/plugins/tests/inline_ctor.txt new file mode 100644 index 0000000000..caa0cb4e3b --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.cpp new file mode 100644 index 0000000000..8ee2fb2ac8 --- /dev/null +++ b/third_party/libwebrtc/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 <string> +#include <vector> + +// We don't warn on classes that use default ctors in cpp files. +class MissingInCPPOK { + public: + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +int main() { + MissingInCPPOK one; + MissingCtorsArentOKInHeader two; + return 0; +} diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.h b/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.h new file mode 100644 index 0000000000..1050457a1a --- /dev/null +++ b/third_party/libwebrtc/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 <string> +#include <vector> + +class MissingCtorsArentOKInHeader { + public: + + private: + std::vector<int> one_; + std::vector<std::string> two_; +}; + +#endif // MISSING_CTOR_H_ diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.txt b/third_party/libwebrtc/tools/clang/plugins/tests/missing_ctor.txt new file mode 100644 index 0000000000..301449c4ac --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.cpp new file mode 100644 index 0000000000..aa90a95eb3 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.h b/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.h new file mode 100644 index 0000000000..01cfea9232 --- /dev/null +++ b/third_party/libwebrtc/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 <string> +#include <vector> + +// See crbug.com/136863. + +class Foo { + class Bar { + Bar() {} + ~Bar() {} + + std::vector<std::string> a; + }; +}; + +#endif // NESTED_CLASS_INLINE_CTOR_H_ diff --git a/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.txt b/third_party/libwebrtc/tools/clang/plugins/tests/nested_class_inline_ctor.txt new file mode 100644 index 0000000000..39bd6e1dce --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.cpp new file mode 100644 index 0000000000..f572a41733 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.h b/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.h new file mode 100644 index 0000000000..150c79913f --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.txt b/third_party/libwebrtc/tools/clang/plugins/tests/overridden_methods.txt new file mode 100644 index 0000000000..7553ade70e --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/test.sh b/third_party/libwebrtc/tools/clang/plugins/tests/test.sh new file mode 100755 index 0000000000..262ebbba29 --- /dev/null +++ b/third_party/libwebrtc/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}")" \ + "<Path to the llvm build dir, usually Release+Asserts>" + 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/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.cpp b/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.cpp new file mode 100644 index 0000000000..a07cbe4875 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.h b/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.h new file mode 100644 index 0000000000..d9fbf96ed3 --- /dev/null +++ b/third_party/libwebrtc/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/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.txt b/third_party/libwebrtc/tools/clang/plugins/tests/virtual_methods.txt new file mode 100644 index 0000000000..571d6d667d --- /dev/null +++ b/third_party/libwebrtc/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. |