<p dir="ltr">Will add this and other clang-tidy-related news to the release notes. Any ideas why there's no separate release notes file for clang-tools-extra?</p>
<div class="gmail_quote">On Dec 17, 2015 9:47 PM, "Justin Bogner" <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Alexander Kornienko via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> writes:<br>
> alexfh created this revision.<br>
> alexfh added a reviewer: klimek.<br>
> alexfh added a subscriber: cfe-commits.<br>
><br>
> clang-modernize transforms have moved to clang-tidy. Removing<br>
> the old tool now.<br>
<br>
Please add a note to the release notes mentioning this.<br>
<br>
> <a href="http://reviews.llvm.org/D15606" rel="noreferrer" target="_blank">http://reviews.llvm.org/D15606</a><br>
><br>
> Files:<br>
> CMakeLists.txt<br>
> Makefile<br>
> clang-modernize/<br>
> clang-modernize/AddOverride/<br>
> clang-modernize/AddOverride/AddOverride.cpp<br>
> clang-modernize/AddOverride/AddOverride.h<br>
> clang-modernize/AddOverride/AddOverrideActions.cpp<br>
> clang-modernize/AddOverride/AddOverrideActions.h<br>
> clang-modernize/AddOverride/AddOverrideMatchers.cpp<br>
> clang-modernize/AddOverride/AddOverrideMatchers.h<br>
> clang-modernize/CMakeLists.txt<br>
> clang-modernize/Core/<br>
> clang-modernize/Core/CMakeLists.txt<br>
> clang-modernize/Core/CustomMatchers.h<br>
> clang-modernize/Core/IncludeDirectives.cpp<br>
> clang-modernize/Core/IncludeDirectives.h<br>
> clang-modernize/Core/IncludeExcludeInfo.cpp<br>
> clang-modernize/Core/IncludeExcludeInfo.h<br>
> clang-modernize/Core/Makefile<br>
> clang-modernize/Core/PerfSupport.cpp<br>
> clang-modernize/Core/PerfSupport.h<br>
> clang-modernize/Core/Refactoring.h<br>
> clang-modernize/Core/ReplacementHandling.cpp<br>
> clang-modernize/Core/ReplacementHandling.h<br>
> clang-modernize/Core/Transform.cpp<br>
> clang-modernize/Core/Transform.h<br>
> clang-modernize/Core/Transforms.cpp<br>
> clang-modernize/Core/Transforms.h<br>
> clang-modernize/LoopConvert/<br>
> clang-modernize/LoopConvert/LoopActions.cpp<br>
> clang-modernize/LoopConvert/LoopActions.h<br>
> clang-modernize/LoopConvert/LoopConvert.cpp<br>
> clang-modernize/LoopConvert/LoopConvert.h<br>
> clang-modernize/LoopConvert/LoopMatchers.cpp<br>
> clang-modernize/LoopConvert/LoopMatchers.h<br>
> clang-modernize/LoopConvert/StmtAncestor.cpp<br>
> clang-modernize/LoopConvert/StmtAncestor.h<br>
> clang-modernize/LoopConvert/VariableNaming.cpp<br>
> clang-modernize/LoopConvert/VariableNaming.h<br>
> clang-modernize/Makefile<br>
> clang-modernize/PassByValue/<br>
> clang-modernize/PassByValue/PassByValue.cpp<br>
> clang-modernize/PassByValue/PassByValue.h<br>
> clang-modernize/PassByValue/PassByValueActions.cpp<br>
> clang-modernize/PassByValue/PassByValueActions.h<br>
> clang-modernize/PassByValue/PassByValueMatchers.cpp<br>
> clang-modernize/PassByValue/PassByValueMatchers.h<br>
> clang-modernize/ReplaceAutoPtr/<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.cpp<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.h<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrActions.cpp<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrActions.h<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp<br>
> clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.h<br>
> clang-modernize/UseAuto/<br>
> clang-modernize/UseAuto/UseAuto.cpp<br>
> clang-modernize/UseAuto/UseAuto.h<br>
> clang-modernize/UseAuto/UseAutoActions.cpp<br>
> clang-modernize/UseAuto/UseAutoActions.h<br>
> clang-modernize/UseAuto/UseAutoMatchers.cpp<br>
> clang-modernize/UseAuto/UseAutoMatchers.h<br>
> clang-modernize/UseNullptr/<br>
> clang-modernize/UseNullptr/NullptrActions.cpp<br>
> clang-modernize/UseNullptr/NullptrActions.h<br>
> clang-modernize/UseNullptr/NullptrMatchers.cpp<br>
> clang-modernize/UseNullptr/NullptrMatchers.h<br>
> clang-modernize/UseNullptr/UseNullptr.cpp<br>
> clang-modernize/UseNullptr/UseNullptr.h<br>
> clang-modernize/tool/<br>
> clang-modernize/tool/CMakeLists.txt<br>
> clang-modernize/tool/ClangModernize.cpp<br>
> clang-modernize/tool/Makefile<br>
> docs/AddOverrideTransform.rst<br>
> docs/LoopConvertTransform.rst<br>
> docs/MigratorUsage.rst<br>
> docs/ModernizerUsage.rst<br>
> docs/PassByValueTransform.rst<br>
> docs/ReplaceAutoPtrTransform.rst<br>
> docs/UseAutoTransform.rst<br>
> docs/UseNullptrTransform.rst<br>
> docs/clang-modernize.rst<br>
> docs/cpp11-migrate.rst<br>
> docs/index.rst<br>
> test/CMakeLists.txt<br>
> test/clang-modernize/<br>
> test/clang-modernize/AddOverride/<br>
> test/clang-modernize/AddOverride/basic.cpp<br>
> test/clang-modernize/AddOverride/pure_specifier_fail.cpp<br>
> test/clang-modernize/Combined/<br>
> test/clang-modernize/Combined/combined.cpp<br>
> test/clang-modernize/Combined/compilers.cpp<br>
> test/clang-modernize/Compilations/<br>
> test/clang-modernize/Compilations/Inputs/<br>
> test/clang-modernize/Compilations/Inputs/compilations.cpp<br>
> test/clang-modernize/Compilations/Inputs/compilations_expected.cpp<br>
> test/clang-modernize/Compilations/Inputs/compile_commands.json<br>
> test/clang-modernize/Compilations/Inputs/cpp11.cpp<br>
> test/clang-modernize/Compilations/Inputs/cpp11_expected.cpp<br>
> test/clang-modernize/Compilations/compilation_inc.cpp<br>
> test/clang-modernize/Compilations/compilation_inc_sources.cpp<br>
> test/clang-modernize/Compilations/compilation_not_inc.cpp<br>
> test/clang-modernize/Compilations/detect_from_path.cpp<br>
> test/clang-modernize/Compilations/detect_from_source.cpp<br>
> test/clang-modernize/Compilations/fixed_comp.cpp<br>
> test/clang-modernize/Compilations/fixed_comp_inc.cpp<br>
> test/clang-modernize/Compilations/no_compilation.cpp<br>
> test/clang-modernize/Core/<br>
> test/clang-modernize/Core/Inputs/<br>
> test/clang-modernize/Core/Inputs/.clang-format<br>
> test/clang-modernize/Core/Reformatting.cpp<br>
> test/clang-modernize/HeaderReplacements/<br>
> test/clang-modernize/HeaderReplacements/Inputs/<br>
> test/clang-modernize/HeaderReplacements/Inputs/no_yaml.h<br>
> test/clang-modernize/HeaderReplacements/common.cpp<br>
> test/clang-modernize/HeaderReplacements/common.h<br>
> test/clang-modernize/HeaderReplacements/common_expected.yaml<br>
> test/clang-modernize/HeaderReplacements/main.cpp<br>
> test/clang-modernize/HeaderReplacements/main_expected.yaml<br>
> test/clang-modernize/HeaderReplacements/no_yaml.cpp<br>
> test/clang-modernize/LoopConvert/<br>
> test/clang-modernize/LoopConvert/Inputs/<br>
> test/clang-modernize/LoopConvert/Inputs/macro_problem.h<br>
> test/clang-modernize/LoopConvert/Inputs/negative-header.h<br>
> test/clang-modernize/LoopConvert/Inputs/structures.h<br>
> test/clang-modernize/LoopConvert/array.cpp<br>
> test/clang-modernize/LoopConvert/confidence.cpp<br>
> test/clang-modernize/LoopConvert/dependency.cpp<br>
> test/clang-modernize/LoopConvert/free_begin_end_fail.cpp<br>
> test/clang-modernize/LoopConvert/iterator.cpp<br>
> test/clang-modernize/LoopConvert/macro_problem.cpp<br>
> test/clang-modernize/LoopConvert/naming-alias.cpp<br>
> test/clang-modernize/LoopConvert/naming-conflict.cpp<br>
> test/clang-modernize/LoopConvert/negative-iterator.cpp<br>
> test/clang-modernize/LoopConvert/negative-multi-end-call.cpp<br>
> test/clang-modernize/LoopConvert/negative-pseudoarray-extra.cpp<br>
> test/clang-modernize/LoopConvert/negative-pseudoarray.cpp<br>
> test/clang-modernize/LoopConvert/negative.cpp<br>
> test/clang-modernize/LoopConvert/nesting.cpp<br>
> test/clang-modernize/LoopConvert/nocompile.cpp<br>
> test/clang-modernize/LoopConvert/pseudoarray.cpp<br>
> test/clang-modernize/LoopConvert/single-iterator.cpp<br>
> test/clang-modernize/PassByValue/<br>
> test/clang-modernize/PassByValue/basic.cpp<br>
> test/clang-modernize/PassByValue/basic.h<br>
> test/clang-modernize/ReplaceAutoPtr/<br>
> test/clang-modernize/ReplaceAutoPtr/Inputs/<br>
> test/clang-modernize/ReplaceAutoPtr/Inputs/basic.h<br>
> test/clang-modernize/ReplaceAutoPtr/Inputs/memory_stub.h<br>
> test/clang-modernize/ReplaceAutoPtr/basic.cpp<br>
> test/clang-modernize/ReplaceAutoPtr/move.cpp<br>
> test/clang-modernize/ReplaceAutoPtr/template_fail.cpp<br>
> test/clang-modernize/UseAuto/<br>
> test/clang-modernize/UseAuto/Inputs/<br>
> test/clang-modernize/UseAuto/Inputs/test_std_container.h<br>
> test/clang-modernize/UseAuto/basic_iterator_tests.cpp<br>
> test/clang-modernize/UseAuto/iterator.cpp<br>
> test/clang-modernize/UseAuto/new.cpp<br>
> test/clang-modernize/UseAuto/new_cv_failing.cpp<br>
> test/clang-modernize/UseNullptr/<br>
> test/clang-modernize/UseNullptr/Inputs/<br>
> test/clang-modernize/UseNullptr/Inputs/basic.h<br>
> test/clang-modernize/UseNullptr/basic.cpp<br>
> test/clang-modernize/UseNullptr/basic_failing.cpp<br>
> test/clang-modernize/UseNullptr/macros.cpp<br>
> test/clang-modernize/UseNullptr/nullptr_t.cpp<br>
> unittests/CMakeLists.txt<br>
> unittests/Makefile<br>
> unittests/clang-modernize/<br>
> unittests/clang-modernize/CMakeLists.txt<br>
> unittests/clang-modernize/IncludeDirectivesTest.cpp<br>
> unittests/clang-modernize/IncludeExcludeTest.cpp<br>
> unittests/clang-modernize/Makefile<br>
> unittests/clang-modernize/PerfSupportTest.cpp<br>
> unittests/clang-modernize/TransformTest.cpp<br>
> unittests/clang-modernize/UniqueHeaderNameTest.cpp<br>
> unittests/include/common/Utility.h<br>
><br>
> Index: unittests/include/common/Utility.h<br>
> ===================================================================<br>
> --- unittests/include/common/Utility.h<br>
> +++ /dev/null<br>
> @@ -1,25 +0,0 @@<br>
> -//=-- clang-modernize/Utility.h - Utility functions and macros---*- C++ -*-===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef CLANG_MODERNIZE_UNITTESTS_UTILITY_H<br>
> -#define CLANG_MODERNIZE_UNITTESTS_UTILITY_H<br>
> -<br>
> -// FIXME: copied from unittests/Support/Path.cpp<br>
> -#define ASSERT_NO_ERROR(x) \<br>
> - if (std::error_code ASSERT_NO_ERROR_ec = x) { \<br>
> - llvm::SmallString<128> MessageStorage; \<br>
> - llvm::raw_svector_ostream Message(MessageStorage); \<br>
> - Message << #x ": did not return errc::success.\n" \<br>
> - << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \<br>
> - << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \<br>
> - GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \<br>
> - } else { \<br>
> - }<br>
> -<br>
> -#endif // CLANG_MODERNIZE_UNITTESTS_UTILITY_H<br>
> Index: unittests/clang-modernize/UniqueHeaderNameTest.cpp<br>
> ===================================================================<br>
> --- unittests/clang-modernize/UniqueHeaderNameTest.cpp<br>
> +++ /dev/null<br>
> @@ -1,61 +0,0 @@<br>
> -//===- unittests/clang-modernize/UniqueHeaderNameTest.cpp -----------------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// Test for the generateReplacementsFileName() in FileOverrides.h<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "gtest/gtest.h"<br>
> -#include "Core/ReplacementHandling.h"<br>
> -#include "llvm/Support/FileSystem.h"<br>
> -#include "llvm/Support/Path.h"<br>
> -#include "llvm/Support/Regex.h"<br>
> -#include <system_error><br>
> -<br>
> -TEST(UniqueHeaderName, testUniqueHeaderName) {<br>
> - using namespace llvm::sys::path;<br>
> -<br>
> - llvm::SmallString<32> TmpDir;<br>
> - system_temp_directory(true, TmpDir);<br>
> -<br>
> - llvm::SmallString<128> SourceFile(TmpDir);<br>
> - append(SourceFile, "project/lib/feature.cpp");<br>
> - native(SourceFile.str().str(), SourceFile);<br>
> -<br>
> - llvm::SmallString<128> DestDir(TmpDir);<br>
> - append(DestDir, "replacements");<br>
> -<br>
> - llvm::SmallString<128> FullActualPath;<br>
> - llvm::SmallString<128> Error;<br>
> - bool Result = ReplacementHandling::generateReplacementsFileName(<br>
> - DestDir, SourceFile, FullActualPath, Error);<br>
> -<br>
> - ASSERT_TRUE(Result);<br>
> - EXPECT_TRUE(Error.empty());<br>
> -<br>
> - // We need to check the directory name and filename separately since on<br>
> - // Windows, the path separator is '\' which is a regex escape character.<br>
> - llvm::SmallString<128> ExpectedPath =<br>
> - llvm::sys::path::parent_path(SourceFile);<br>
> - llvm::SmallString<128> ActualPath =<br>
> - llvm::sys::path::parent_path(FullActualPath);<br>
> - llvm::SmallString<128> ActualName =<br>
> - llvm::sys::path::filename(FullActualPath);<br>
> -<br>
> - EXPECT_STREQ(DestDir.c_str(), ActualPath.c_str());<br>
> -<br>
> - llvm::StringRef ExpectedName =<br>
> - "^feature.cpp_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_["<br>
> - "0-9a-f]{2}_[0-9a-f]{2}.yaml$";<br>
> - llvm::Regex R(ExpectedName);<br>
> - ASSERT_TRUE(R.match(ActualName))<br>
> - << "ExpectedName: " << ExpectedName.data()<br>
> - << "\nActualName: " << ActualName.c_str();<br>
> - ASSERT_TRUE(Error.empty()) << "Error: " << Error.c_str();<br>
> -}<br>
> Index: unittests/clang-modernize/TransformTest.cpp<br>
> ===================================================================<br>
> --- unittests/clang-modernize/TransformTest.cpp<br>
> +++ /dev/null<br>
> @@ -1,299 +0,0 @@<br>
> -//===- clang-modernize/TransformTest.cpp - Transform unit tests -----------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "gtest/gtest.h"<br>
> -#include "Core/Transform.h"<br>
> -#include "clang/AST/ASTConsumer.h"<br>
> -#include "clang/AST/DeclGroup.h"<br>
> -#include "clang/ASTMatchers/ASTMatchFinder.h"<br>
> -#include "clang/ASTMatchers/ASTMatchers.h"<br>
> -#include "llvm/Support/FileSystem.h"<br>
> -#include "llvm/Support/Path.h"<br>
> -#include "llvm/Support/Process.h"<br>
> -<br>
> -using namespace clang;<br>
> -using namespace ast_matchers;<br>
> -<br>
> -class DummyTransform : public Transform {<br>
> -public:<br>
> - DummyTransform(llvm::StringRef Name, const TransformOptions &Options)<br>
> - : Transform(Name, Options) {}<br>
> -<br>
> - int apply(const tooling::CompilationDatabase &,<br>
> - const std::vector<std::string> &) override {<br>
> - return 0;<br>
> - }<br>
> -<br>
> - void setAcceptedChanges(unsigned Changes) {<br>
> - Transform::setAcceptedChanges(Changes);<br>
> - }<br>
> - void setRejectedChanges(unsigned Changes) {<br>
> - Transform::setRejectedChanges(Changes);<br>
> - }<br>
> - void setDeferredChanges(unsigned Changes) {<br>
> - Transform::setDeferredChanges(Changes);<br>
> - }<br>
> -<br>
> -};<br>
> -<br>
> -TEST(Transform, Interface) {<br>
> - TransformOptions Options;<br>
> - DummyTransform T("my_transform", Options);<br>
> -<br>
> - ASSERT_EQ("my_transform", T.getName());<br>
> - ASSERT_EQ(0u, T.getAcceptedChanges());<br>
> - ASSERT_EQ(0u, T.getRejectedChanges());<br>
> - ASSERT_EQ(0u, T.getDeferredChanges());<br>
> - ASSERT_FALSE(T.getChangesMade());<br>
> - ASSERT_FALSE(T.getChangesNotMade());<br>
> -<br>
> - T.setAcceptedChanges(1);<br>
> - ASSERT_TRUE(T.getChangesMade());<br>
> -<br>
> - T.setDeferredChanges(1);<br>
> - ASSERT_TRUE(T.getChangesNotMade());<br>
> -<br>
> - T.setRejectedChanges(1);<br>
> - ASSERT_TRUE(T.getChangesNotMade());<br>
> -<br>
> - T.Reset();<br>
> - ASSERT_EQ(0u, T.getAcceptedChanges());<br>
> - ASSERT_EQ(0u, T.getRejectedChanges());<br>
> - ASSERT_EQ(0u, T.getDeferredChanges());<br>
> -<br>
> - T.setRejectedChanges(1);<br>
> - ASSERT_TRUE(T.getChangesNotMade());<br>
> -}<br>
> -<br>
> -class TimePassingASTConsumer : public ASTConsumer {<br>
> -public:<br>
> - TimePassingASTConsumer(bool *Called) : Called(Called) {}<br>
> -<br>
> - bool HandleTopLevelDecl(DeclGroupRef DeclGroup) override {<br>
> - llvm::sys::TimeValue UserStart;<br>
> - llvm::sys::TimeValue SystemStart;<br>
> - llvm::sys::TimeValue UserNow;<br>
> - llvm::sys::TimeValue SystemNow;<br>
> - llvm::sys::TimeValue Wall;<br>
> -<br>
> - // Busy-wait until the user/system time combined is more than 1ms<br>
> - llvm::sys::TimeValue OneMS(0, 1000000);<br>
> - llvm::sys::Process::GetTimeUsage(Wall, UserStart, SystemStart);<br>
> - do {<br>
> - llvm::sys::Process::GetTimeUsage(Wall, UserNow, SystemNow);<br>
> - } while (UserNow - UserStart + SystemNow - SystemStart < OneMS);<br>
> - *Called = true;<br>
> - return true;<br>
> - }<br>
> - bool *Called;<br>
> -};<br>
> -<br>
> -struct ConsumerFactory {<br>
> - std::unique_ptr<ASTConsumer> newASTConsumer() {<br>
> - return llvm::make_unique<TimePassingASTConsumer>(&Called);<br>
> - }<br>
> - bool Called;<br>
> -};<br>
> -<br>
> -struct CallbackForwarder : public clang::tooling::SourceFileCallbacks {<br>
> - CallbackForwarder(Transform &Callee) : Callee(Callee) {}<br>
> -<br>
> - bool handleBeginSource(CompilerInstance &CI, StringRef Filename) override {<br>
> - return Callee.handleBeginSource(CI, Filename);<br>
> - }<br>
> -<br>
> - void handleEndSource() override { Callee.handleEndSource(); }<br>
> -<br>
> - Transform &Callee;<br>
> -};<br>
> -<br>
> -TEST(Transform, Timings) {<br>
> - TransformOptions Options;<br>
> - Options.EnableTiming = true;<br>
> - DummyTransform T("timing_transform", Options);<br>
> -<br>
> - // All the path stuff is to make the test work independently of OS.<br>
> -<br>
> - // The directory used is not important since the path gets mapped to a virtual<br>
> - // file anyway. What is important is that we have an absolute path with which<br>
> - // to use with mapVirtualFile().<br>
> - SmallString<128> CurrentDir;<br>
> - std::error_code EC = llvm::sys::fs::current_path(CurrentDir);<br>
> - assert(!EC);<br>
> - (void)EC;<br>
> -<br>
> - SmallString<128> FileA = CurrentDir;<br>
> - llvm::sys::path::append(FileA, "a.cc");<br>
> -<br>
> - SmallString<128> FileB = CurrentDir;<br>
> - llvm::sys::path::append(FileB, "b.cc");<br>
> -<br>
> - tooling::FixedCompilationDatabase Compilations(CurrentDir.str(),<br>
> - std::vector<std::string>());<br>
> - std::vector<std::string> Sources;<br>
> - Sources.push_back(FileA.str());<br>
> - Sources.push_back(FileB.str());<br>
> - tooling::ClangTool Tool(Compilations, Sources);<br>
> -<br>
> - Tool.mapVirtualFile(FileA, "void a() {}");<br>
> - Tool.mapVirtualFile(FileB, "void b() {}");<br>
> -<br>
> - // Factory to create TimePassingASTConsumer for each source file the tool<br>
> - // runs on.<br>
> - ConsumerFactory Factory;<br>
> -<br>
> - // We don't care about any of Transform's functionality except to get it to<br>
> - // record timings. For that, we need to forward handleBeginSource() and<br>
> - // handleEndSource() calls to it.<br>
> - CallbackForwarder Callbacks(T);<br>
> -<br>
> - Tool.run(<br>
> - clang::tooling::newFrontendActionFactory(&Factory, &Callbacks).get());<br>
> -<br>
> - EXPECT_TRUE(Factory.Called);<br>
> - Transform::TimingVec::const_iterator I = T.timing_begin();<br>
> - EXPECT_GT(I->second.getProcessTime(), 0.0);<br>
> -<br>
> - // The success of the test shouldn't depend on the order of iteration through<br>
> - // timers.<br>
> - StringRef FirstFile = I->first;<br>
> - if (FileA == FirstFile) {<br>
> - ++I;<br>
> - EXPECT_EQ(FileB, I->first);<br>
> - EXPECT_GT(I->second.getProcessTime(), 0.0);<br>
> - } else if (FileB == FirstFile) {<br>
> - ++I;<br>
> - EXPECT_EQ(FileA, I->first);<br>
> - EXPECT_GT(I->second.getProcessTime(), 0.0);<br>
> - } else {<br>
> - FAIL() << "Unexpected file name " << I->first << " in timing data.";<br>
> - }<br>
> - ++I;<br>
> - EXPECT_EQ(T.timing_end(), I);<br>
> -}<br>
> -<br>
> -class ModifiableCallback<br>
> - : public clang::ast_matchers::MatchFinder::MatchCallback {<br>
> -public:<br>
> - ModifiableCallback(const Transform &Owner)<br>
> - : Owner(Owner) {}<br>
> -<br>
> - void<br>
> - run(const clang::ast_matchers::MatchFinder::MatchResult &Result) override {<br>
> - const VarDecl *Decl = Result.Nodes.getNodeAs<VarDecl>("decl");<br>
> - ASSERT_TRUE(Decl != nullptr);<br>
> -<br>
> - const SourceManager &SM = *Result.SourceManager;<br>
> -<br>
> - // Decl 'a' comes from the main source file. This test should always pass.<br>
> - if (Decl->getName().equals("a"))<br>
> - EXPECT_TRUE(Owner.isFileModifiable(SM, Decl->getLocStart()));<br>
> -<br>
> - // Decl 'c' comes from an excluded header. This test should never pass.<br>
> - else if (Decl->getName().equals("c"))<br>
> - EXPECT_FALSE(Owner.isFileModifiable(SM, Decl->getLocStart()));<br>
> -<br>
> - // Decl 'b' comes from an included header.<br>
> - else if (Decl->getName().equals("b"))<br>
> - EXPECT_TRUE(Owner.isFileModifiable(SM, Decl->getLocStart()));<br>
> -<br>
> - // Make sure edge cases are handled gracefully (they should never be<br>
> - // allowed).<br>
> - SourceLocation DummyLoc;<br>
> - EXPECT_FALSE(Owner.isFileModifiable(SM, DummyLoc));<br>
> - }<br>
> -<br>
> -private:<br>
> - const Transform &Owner;<br>
> -};<br>
> -<br>
> -TEST(Transform, isFileModifiable) {<br>
> - TransformOptions Options;<br>
> -<br>
> - ///<br>
> - /// SETUP<br>
> - ///<br>
> - /// To test Transform::isFileModifiable() we need a SourceManager primed with<br>
> - /// actual files and SourceLocations to test. Easiest way to accomplish this<br>
> - /// is to use Tooling classes.<br>
> - ///<br>
> - /// 1) Simulate a source file that includes two headers, one that is allowed<br>
> - /// to be modified and the other that is not allowed. Each of the three<br>
> - /// files involved will declare a single variable with a different name.<br>
> - /// 2) A matcher is created to find VarDecls.<br>
> - /// 3) A MatchFinder callback calls Transform::isFileModifiable() with the<br>
> - /// SourceLocations of found VarDecls and thus tests the function.<br>
> - ///<br>
> -<br>
> - // All the path stuff is to make the test work independently of OS.<br>
> -<br>
> - // The directory used is not important since the path gets mapped to a virtual<br>
> - // file anyway. What is important is that we have an absolute path with which<br>
> - // to use with mapVirtualFile().<br>
> - SmallString<128> CurrentDir;<br>
> - std::error_code EC = llvm::sys::fs::current_path(CurrentDir);<br>
> - assert(!EC);<br>
> - (void)EC;<br>
> -<br>
> - SmallString<128> SourceFile = CurrentDir;<br>
> - llvm::sys::path::append(SourceFile, "a.cc");<br>
> -<br>
> - SmallString<128> HeaderFile = CurrentDir;<br>
> - llvm::sys::path::append(HeaderFile, "a.h");<br>
> -<br>
> - SmallString<128> HeaderBFile = CurrentDir;<br>
> - llvm::sys::path::append(HeaderBFile, "temp");<br>
> - llvm::sys::path::append(HeaderBFile, "b.h");<br>
> -<br>
> - StringRef ExcludeDir = llvm::sys::path::parent_path(HeaderBFile);<br>
> -<br>
> - IncludeExcludeInfo IncInfo;<br>
> - Options.ModifiableFiles.readListFromString(CurrentDir, ExcludeDir);<br>
> -<br>
> - tooling::FixedCompilationDatabase Compilations(CurrentDir.str(),<br>
> - std::vector<std::string>());<br>
> - std::vector<std::string> Sources;<br>
> - Sources.push_back(SourceFile.str());<br>
> - tooling::ClangTool Tool(Compilations, Sources);<br>
> -<br>
> - Tool.mapVirtualFile(SourceFile,<br>
> - "#include \"a.h\"\n"<br>
> - "#include \"temp/b.h\"\n"<br>
> - "int a;");<br>
> - Tool.mapVirtualFile(HeaderFile, "int b;");<br>
> - Tool.mapVirtualFile(HeaderBFile, "int c;");<br>
> -<br>
> - DummyTransform T("dummy", Options);<br>
> - MatchFinder Finder;<br>
> - ModifiableCallback Callback(T);<br>
> - Finder.addMatcher(varDecl().bind("decl"), &Callback);<br>
> - Tool.run(tooling::newFrontendActionFactory(&Finder).get());<br>
> -}<br>
> -<br>
> -TEST(VersionTest, Interface) {<br>
> - Version V;<br>
> -<br>
> - ASSERT_TRUE(V.isNull());<br>
> - ASSERT_TRUE(Version(1) < Version(1, 1));<br>
> - ASSERT_TRUE(Version(1) < Version(2));<br>
> - ASSERT_TRUE(Version(1, 1) < Version(2));<br>
> - ASSERT_TRUE(Version(1, 1) == Version(1, 1));<br>
> - ASSERT_EQ(Version(1).getMajor(), unsigned(1));<br>
> - ASSERT_EQ(Version(1).getMinor(), unsigned(0));<br>
> - ASSERT_EQ(Version(1, 2).getMinor(), unsigned(2));<br>
> -}<br>
> -<br>
> -TEST(VersionTest, getFromString) {<br>
> - ASSERT_EQ(Version(1), Version::getFromString("1"));<br>
> - ASSERT_EQ(Version(1, 2), Version::getFromString("1.2"));<br>
> - ASSERT_TRUE(Version::getFromString("foo").isNull());<br>
> - ASSERT_TRUE(Version::getFromString("1bar").isNull());<br>
> - // elements after major.minor are ignored<br>
> - ASSERT_EQ(Version(1, 2), Version::getFromString("1.2.3"));<br>
> -}<br>
> Index: unittests/clang-modernize/PerfSupportTest.cpp<br>
> ===================================================================<br>
> --- unittests/clang-modernize/PerfSupportTest.cpp<br>
> +++ /dev/null<br>
> @@ -1,97 +0,0 @@<br>
> -//===- clang-modernize/PerfSupportTest.cpp - PerfSupport unit tests -------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "gtest/gtest.h"<br>
> -#include "Core/PerfSupport.h"<br>
> -<br>
> -using namespace llvm;<br>
> -using namespace clang;<br>
> -<br>
> -class TransformA : public Transform {<br>
> -public:<br>
> - TransformA(const TransformOptions &Options)<br>
> - : Transform("TransformA", Options) {}<br>
> -<br>
> - int apply(const tooling::CompilationDatabase &,<br>
> - const std::vector<std::string> &) override {<br>
> - return 0;<br>
> - }<br>
> -<br>
> - void addTiming(StringRef Label, TimeRecord Duration) {<br>
> - Transform::addTiming(Label, Duration);<br>
> - }<br>
> -};<br>
> -<br>
> -class TransformB : public Transform {<br>
> -public:<br>
> - TransformB(const TransformOptions &Options)<br>
> - : Transform("TransformB", Options) {}<br>
> -<br>
> - int apply(const tooling::CompilationDatabase &,<br>
> - const std::vector<std::string> &) override {<br>
> - return 0;<br>
> - }<br>
> -<br>
> - void addTiming(StringRef Label, TimeRecord Duration) {<br>
> - Transform::addTiming(Label, Duration);<br>
> - }<br>
> -};<br>
> -<br>
> -struct ExpectedResults {<br>
> - const char *SourceName;<br>
> - unsigned DataCount;<br>
> - struct Datum {<br>
> - const char *Label;<br>
> - float Duration;<br>
> - } Data[2];<br>
> -};<br>
> -<br>
> -TEST(PerfSupport, collectSourcePerfData) {<br>
> - TransformOptions Options;<br>
> - TransformA A(Options);<br>
> - TransformB B(Options);<br>
> -<br>
> - // The actual durations don't matter. Below only their relative ordering is<br>
> - // tested to ensure times, labels, and sources all stay together properly.<br>
> - A.addTiming("FileA.cpp", TimeRecord::getCurrentTime(/*Start=*/true));<br>
> - A.addTiming("FileC.cpp", TimeRecord::getCurrentTime(/*Start=*/true));<br>
> - B.addTiming("FileC.cpp", TimeRecord::getCurrentTime(/*Start=*/true));<br>
> - B.addTiming("FileB.cpp", TimeRecord::getCurrentTime(/*Start=*/true));<br>
> -<br>
> - SourcePerfData PerfData;<br>
> - collectSourcePerfData(A, PerfData);<br>
> -<br>
> - SourcePerfData::const_iterator FileAI = PerfData.find("FileA.cpp");<br>
> - EXPECT_NE(FileAI, PerfData.end());<br>
> - SourcePerfData::const_iterator FileCI = PerfData.find("FileC.cpp");<br>
> - EXPECT_NE(FileCI, PerfData.end());<br>
> - EXPECT_EQ(2u, PerfData.size());<br>
> -<br>
> - EXPECT_EQ(1u, FileAI->second.size());<br>
> - EXPECT_EQ("TransformA", FileAI->second[0].Label);<br>
> - EXPECT_EQ(1u, FileCI->second.size());<br>
> - EXPECT_EQ("TransformA", FileCI->second[0].Label);<br>
> - EXPECT_LE(FileAI->second[0].Duration, FileCI->second[0].Duration);<br>
> -<br>
> - collectSourcePerfData(B, PerfData);<br>
> -<br>
> - SourcePerfData::const_iterator FileBI = PerfData.find("FileB.cpp");<br>
> - EXPECT_NE(FileBI, PerfData.end());<br>
> - EXPECT_EQ(3u, PerfData.size());<br>
> -<br>
> - EXPECT_EQ(1u, FileAI->second.size());<br>
> - EXPECT_EQ("TransformA", FileAI->second[0].Label);<br>
> - EXPECT_EQ(2u, FileCI->second.size());<br>
> - EXPECT_EQ("TransformA", FileCI->second[0].Label);<br>
> - EXPECT_EQ("TransformB", FileCI->second[1].Label);<br>
> - EXPECT_LE(FileCI->second[0].Duration, FileCI->second[1].Duration);<br>
> - EXPECT_EQ(1u, FileBI->second.size());<br>
> - EXPECT_EQ("TransformB", FileBI->second[0].Label);<br>
> - EXPECT_LE(FileCI->second[1].Duration, FileBI->second[0].Duration);<br>
> -}<br>
> Index: unittests/clang-modernize/Makefile<br>
> ===================================================================<br>
> --- unittests/clang-modernize/Makefile<br>
> +++ /dev/null<br>
> @@ -1,27 +0,0 @@<br>
> -##===- unittests/clang-modernize/Makefile ------------------*- Makefile -*-===##<br>
> -#<br>
> -# The LLVM Compiler Infrastructure<br>
> -#<br>
> -# This file is distributed under the University of Illinois Open Source<br>
> -# License. See LICENSE.TXT for details.<br>
> -#<br>
> -##===----------------------------------------------------------------------===##<br>
> -<br>
> -CLANG_LEVEL = ../../../..<br>
> -include $(CLANG_LEVEL)/../../Makefile.config<br>
> -<br>
> -TESTNAME = ClangModernizeTests<br>
> -LINK_COMPONENTS := asmparser bitreader support MC MCParser option \<br>
> - TransformUtils<br>
> -USEDLIBS = modernizeCore.a clangFormat.a clangApplyReplacements.a \<br>
> - clangTooling.a clangToolingCore.a clangFrontend.a \<br>
> - clangSerialization.a clangDriver.a clangRewriteFrontend.a \<br>
> - clangRewrite.a clangParse.a clangSema.a clangAnalysis.a \<br>
> - clangAST.a clangASTMatchers.a clangEdit.a clangLex.a \<br>
> - clangBasic.a<br>
> -<br>
> -include $(CLANG_LEVEL)/Makefile<br>
> -MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1<br>
> -CPP.Flags += -I$(PROJ_SRC_DIR)/../../clang-modernize -I$(PROJ_SRC_DIR)/../../clang-apply-replacements/include \<br>
> - -I$(PROJ_SRC_DIR)/../include<br>
> -include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest<br>
> Index: unittests/clang-modernize/IncludeExcludeTest.cpp<br>
> ===================================================================<br>
> --- unittests/clang-modernize/IncludeExcludeTest.cpp<br>
> +++ /dev/null<br>
> @@ -1,149 +0,0 @@<br>
> -//===- clang-modernize/IncludeExcludeTest.cpp - IncludeExclude unit tests -===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "common/Utility.h"<br>
> -#include "Core/IncludeExcludeInfo.h"<br>
> -#include "llvm/Support/FileSystem.h"<br>
> -#include "llvm/Support/Path.h"<br>
> -#include "gtest/gtest.h"<br>
> -#include <fstream><br>
> -<br>
> -TEST(IncludeExcludeTest, ParseString) {<br>
> - IncludeExcludeInfo IEManager;<br>
> - std::error_code Err = IEManager.readListFromString(<br>
> - /*include=*/ "a,b/b2,c/c2,d/../d2/../d3",<br>
> - /*exclude=*/ "a/af.cpp,a/a2,b/b2/b2f.cpp,c/c2");<br>
> -<br>
> - ASSERT_EQ(Err, std::error_code());<br>
> -<br>
> - // If the file does not appear on the include list then it is not safe to<br>
> - // transform. Files are not safe to transform by default.<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("b/dir/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("d/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("d2/f.cpp"));<br>
> -<br>
> - // If the file appears on only the include list then it is safe to transform.<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/dir/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("b/b2/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("d3/f.cpp"));<br>
> -<br>
> - // If the file appears on both the include or exclude list then it is not<br>
> - // safe to transform.<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("a/a2/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("a/a2/dir/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("b/b2/b2f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("c/c2/c3/f.cpp"));<br>
> -<br>
> -#ifdef LLVM_ON_WIN32<br>
> - // Check for cases when the path separators are different between the path<br>
> - // that was read and the path that we are checking for. This can happen on<br>
> - // windows where lit provides "\" and the test has "/".<br>
> - ASSERT_NO_ERROR(IEManager.readListFromString(<br>
> - /*include=*/ "C:\\foo,a\\b/c,a/../b\\c/..\\d",<br>
> - /*exclude=*/ "C:\\bar"<br>
> - ));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("C:/foo/code.h"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("C:/bar/code.h"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/b\\c/code.h"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("b\\c/code.h"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("b/d\\code.h"));<br>
> -#endif<br>
> -}<br>
> -<br>
> -TEST(IncludeExcludeTest, ParseStringCases) {<br>
> - IncludeExcludeInfo IEManager;<br>
> - std::error_code Err = IEManager.readListFromString(<br>
> - /*include=*/ "a/.,b/b2/,c/c2/c3/../../c4/,d/d2/./d3/,/e/e2/.",<br>
> - /*exclude=*/ "");<br>
> -<br>
> - ASSERT_EQ(Err, std::error_code());<br>
> -<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("b/b2/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("c/c4/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("d/d2/d3/f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("/e/e2/f.cpp"));<br>
> -<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("c/c2/c3/f.cpp"));<br>
> -}<br>
> -<br>
> -// Utility for creating and filling files with data for IncludeExcludeFileTest<br>
> -// tests.<br>
> -struct InputFiles {<br>
> -<br>
> - // This function uses fatal assertions. The caller is responsible for making<br>
> - // sure fatal assertions propagate.<br>
> - void CreateFiles(bool UnixMode) {<br>
> - llvm::SmallString<128> Path;<br>
> - int FD;<br>
> -<br>
> - ASSERT_NO_ERROR(<br>
> - llvm::sys::fs::createTemporaryFile("include", "", FD, Path));<br>
> - IncludeDataPath = Path.str();<br>
> - {<br>
> - llvm::raw_fd_ostream IncludeDataFile(FD, true);<br>
> - for (unsigned i = 0; i < sizeof(IncludeData) / sizeof(char *); ++i) {<br>
> - IncludeDataFile << IncludeData[i] << (UnixMode ? "\n" : "\r\n");<br>
> - }<br>
> - }<br>
> -<br>
> - ASSERT_NO_ERROR(<br>
> - llvm::sys::fs::createTemporaryFile("exclude", "", FD, Path));<br>
> - ExcludeDataPath = Path.str();<br>
> - {<br>
> - llvm::raw_fd_ostream ExcludeDataFile(FD, true);<br>
> - for (unsigned i = 0; i < sizeof(ExcludeData) / sizeof(char *); ++i) {<br>
> - ExcludeDataFile << ExcludeData[i] << (UnixMode ? "\n" : "\r\n");<br>
> - }<br>
> - }<br>
> - }<br>
> -<br>
> - static const char *IncludeData[3];<br>
> - static const char *ExcludeData[4];<br>
> -<br>
> - std::string IncludeDataPath;<br>
> - std::string ExcludeDataPath;<br>
> -};<br>
> -<br>
> -const char *InputFiles::IncludeData[3] = { "a", "b/b2", "c/c2" };<br>
> -const char *InputFiles::ExcludeData[4] = { "a/af.cpp", "a/a2", "b/b2/b2f.cpp",<br>
> - "c/c2" };<br>
> -<br>
> -TEST(IncludeExcludeFileTest, UNIXFile) {<br>
> - InputFiles UnixFiles;<br>
> - ASSERT_NO_FATAL_FAILURE(UnixFiles.CreateFiles(/* UnixMode= */true));<br>
> -<br>
> - IncludeExcludeInfo IEManager;<br>
> - std::error_code Err = IEManager.readListFromFile(<br>
> - UnixFiles.IncludeDataPath.c_str(), UnixFiles.ExcludeDataPath.c_str());<br>
> -<br>
> - ASSERT_EQ(Err, std::error_code());<br>
> -<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));<br>
> -}<br>
> -<br>
> -TEST(IncludeExcludeFileTest, DOSFile) {<br>
> - InputFiles DOSFiles;<br>
> - ASSERT_NO_FATAL_FAILURE(DOSFiles.CreateFiles(/* UnixMode= */false));<br>
> -<br>
> - IncludeExcludeInfo IEManager;<br>
> - std::error_code Err = IEManager.readListFromFile(<br>
> - DOSFiles.IncludeDataPath.c_str(), DOSFiles.ExcludeDataPath.c_str());<br>
> -<br>
> - ASSERT_EQ(Err, std::error_code());<br>
> -<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));<br>
> - EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));<br>
> - EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));<br>
> -}<br>
> Index: unittests/clang-modernize/IncludeDirectivesTest.cpp<br>
> ===================================================================<br>
> --- unittests/clang-modernize/IncludeDirectivesTest.cpp<br>
> +++ /dev/null<br>
> @@ -1,410 +0,0 @@<br>
> -//===- clang-modernize/IncludeDirectivesTest.cpp --------------------------===//<br>
> -//<br>
> -// The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "Core/IncludeDirectives.h"<br>
> -#include "common/VirtualFileHelper.h"<br>
> -#include "clang/Frontend/CompilerInstance.h"<br>
> -#include "clang/Frontend/FrontendActions.h"<br>
> -#include "llvm/Support/Path.h"<br>
> -#include "gtest/gtest.h"<br>
> -<br>
> -using namespace llvm;<br>
> -using namespace clang;<br>
> -<br>
> -/// \brief A convenience method around \c tooling::runToolOnCodeWithArgs() that<br>
> -/// adds the current directory to the include search paths.<br>
> -static void applyActionOnCode(FrontendAction *ToolAction, StringRef Code) {<br>
> - SmallString<128> CurrentDir;<br>
> - ASSERT_FALSE(llvm::sys::fs::current_path(CurrentDir));<br>
> -<br>
> - // Add the current directory to the header search paths so angled includes can<br>
> - // find them.<br>
> - std::vector<std::string> Args;<br>
> - Args.push_back("-I");<br>
> - Args.push_back(CurrentDir.str().str());<br>
> -<br>
> - // mapVirtualFile() needs absolute path for the input file as well.<br>
> - SmallString<128> InputFile(CurrentDir);<br>
> - sys::path::append(InputFile, "input.cc");<br>
> -<br>
> - ASSERT_TRUE(<br>
> - tooling::runToolOnCodeWithArgs(ToolAction, Code, Args, InputFile.str()));<br>
> -}<br>
> -<br>
> -namespace {<br>
> -class TestAddIncludeAction : public PreprocessOnlyAction {<br>
> -public:<br>
> - TestAddIncludeAction(StringRef Include, tooling::Replacements &Replaces,<br>
> - const char *HeaderToModify = nullptr)<br>
> - : Include(Include), Replaces(Replaces), HeaderToModify(HeaderToModify) {<br>
> - // some headers that the tests can include<br>
> - mapVirtualHeader("foo-inner.h", "#pragma once\n");<br>
> - mapVirtualHeader("foo.h", "#pragma once\n"<br>
> - "#include <foo-inner.h>\n");<br>
> - mapVirtualHeader("bar-inner.h", "#pragma once\n");<br>
> - mapVirtualHeader("bar.h", "#pragma once\n"<br>
> - "#include <bar-inner.h>\n");<br>
> - mapVirtualHeader("xmacro.def", "X(Val1)\n"<br>
> - "X(Val2)\n"<br>
> - "X(Val3)\n");<br>
> - }<br>
> -<br>
> - /// \brief Make \p FileName an absolute path.<br>
> - ///<br>
> - /// Header files are mapped in the current working directory. The current<br>
> - /// working directory is used because it's important to map files with<br>
> - /// absolute paths.<br>
> - ///<br>
> - /// When used in conjunction with \c applyActionOnCode() (which adds the<br>
> - /// current working directory to the header search paths) it is possible to<br>
> - /// refer to the headers by using '\<FileName\>'.<br>
> - std::string makeHeaderFileName(StringRef FileName) const {<br>
> - SmallString<128> Path;<br>
> - std::error_code EC = llvm::sys::fs::current_path(Path);<br>
> - assert(!EC);<br>
> - (void)EC;<br>
> -<br>
> - sys::path::append(Path, FileName);<br>
> - return Path.str().str();<br>
> - }<br>
> -<br>
> - /// \brief Map additional header files.<br>
> - ///<br>
> - /// \sa makeHeaderFileName()<br>
> - void mapVirtualHeader(StringRef FileName, StringRef Content) {<br>
> - VFHelper.mapFile(makeHeaderFileName(FileName), Content);<br>
> - }<br>
> -<br>
> -private:<br>
> - bool BeginSourceFileAction(CompilerInstance &CI,<br>
> - StringRef FileName) override {<br>
> - if (!PreprocessOnlyAction::BeginSourceFileAction(CI, FileName))<br>
> - return false;<br>
> - VFHelper.mapVirtualFiles(CI.getSourceManager());<br>
> -<br>
> - FileToModify =<br>
> - HeaderToModify ? makeHeaderFileName(HeaderToModify) : FileName.str();<br>
> -<br>
> - FileIncludes.reset(new IncludeDirectives(CI));<br>
> - return true;<br>
> - }<br>
> -<br>
> - void EndSourceFileAction() override {<br>
> - const tooling::Replacement &Replace =<br>
> - FileIncludes->addAngledInclude(FileToModify, Include);<br>
> - if (Replace.isApplicable())<br>
> - Replaces.insert(Replace);<br>
> - }<br>
> -<br>
> - StringRef Include;<br>
> - VirtualFileHelper VFHelper;<br>
> - tooling::Replacements &Replaces;<br>
> - std::unique_ptr<IncludeDirectives> FileIncludes;<br>
> - std::string FileToModify;<br>
> - // if non-null, add the include directives in this file instead of the main<br>
> - // file.<br>
> - const char *HeaderToModify;<br>
> -};<br>
> -<br>
> -std::string addIncludeInCode(StringRef Include, StringRef Code) {<br>
> - tooling::Replacements Replaces;<br>
> -<br>
> - applyActionOnCode(new TestAddIncludeAction(Include, Replaces), Code);<br>
> -<br>
> - if (::testing::Test::HasFailure())<br>
> - return "<<unexpected error from applyActionOnCode()>>";<br>
> -<br>
> - return tooling::applyAllReplacements(Code, Replaces);<br>
> -}<br>
> -} // end anonymous namespace<br>
> -<br>
> -TEST(IncludeDirectivesTest2, endOfLinesVariants) {<br>
> - EXPECT_EQ("#include <foo.h>\n"<br>
> - "#include <bar>\n",<br>
> - addIncludeInCode("bar", "#include <foo.h>\n"));<br>
> - EXPECT_EQ("#include <foo.h>\r\n"<br>
> - "#include <bar>\r\n",<br>
> - addIncludeInCode("bar", "#include <foo.h>\r\n"));<br>
> - EXPECT_EQ("#include <foo.h>\r"<br>
> - "#include <bar>\r",<br>
> - addIncludeInCode("bar", "#include <foo.h>\r"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, ppToken) {<br>
> - EXPECT_EQ("#define FOO <foo.h>\n"<br>
> - "#include FOO\n"<br>
> - "#include <bar>\n"<br>
> - "int i;\n",<br>
> - addIncludeInCode("bar", "#define FOO <foo.h>\n"<br>
> - "#include FOO\n"<br>
> - "int i;\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, noFileHeader) {<br>
> - EXPECT_EQ("#include <bar>\n"<br>
> - "\n"<br>
> - "int foo;\n",<br>
> - addIncludeInCode("bar", "int foo;\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, commentBeforeTopMostCode) {<br>
> - EXPECT_EQ("#include <bar>\n"<br>
> - "\n"<br>
> - "// Foo\n"<br>
> - "int foo;\n",<br>
> - addIncludeInCode("bar", "// Foo\n"<br>
> - "int foo;\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, multiLineComment) {<br>
> - EXPECT_EQ("#include <foo.h> /* \n */\n"<br>
> - "#include <bar>\n",<br>
> - addIncludeInCode("bar", "#include <foo.h> /* \n */\n"));<br>
> - EXPECT_EQ("#include <foo.h> /* \n */"<br>
> - "\n#include <bar>",<br>
> - addIncludeInCode("bar", "#include <foo.h> /* \n */"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, multilineCommentWithTrailingSpace) {<br>
> - EXPECT_EQ("#include <foo.h> /*\n*/ \n"<br>
> - "#include <bar>\n",<br>
> - addIncludeInCode("bar", "#include <foo.h> /*\n*/ \n"));<br>
> - EXPECT_EQ("#include <foo.h> /*\n*/ "<br>
> - "\n#include <bar>",<br>
> - addIncludeInCode("bar", "#include <foo.h> /*\n*/ "));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, fileHeaders) {<br>
> - EXPECT_EQ("// this is a header\n"<br>
> - "// some license stuff here\n"<br>
> - "\n"<br>
> - "#include <bar>\n"<br>
> - "\n"<br>
> - "/// \\brief Foo\n"<br>
> - "int foo;\n",<br>
> - addIncludeInCode("bar", "// this is a header\n"<br>
> - "// some license stuff here\n"<br>
> - "\n"<br>
> - "/// \\brief Foo\n"<br>
> - "int foo;\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, preferablyAngledNextToAngled) {<br>
> - EXPECT_EQ("#include <foo.h>\n"<br>
> - "#include <bar>\n"<br>
> - "#include \"bar.h\"\n",<br>
> - addIncludeInCode("bar", "#include <foo.h>\n"<br>
> - "#include \"bar.h\"\n"));<br>
> - EXPECT_EQ("#include \"foo.h\"\n"<br>
> - "#include \"bar.h\"\n"<br>
> - "#include <bar>\n",<br>
> - addIncludeInCode("bar", "#include \"foo.h\"\n"<br>
> - "#include \"bar.h\"\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, avoidDuplicates) {<br>
> - EXPECT_EQ("#include <foo.h>\n",<br>
> - addIncludeInCode("foo.h", "#include <foo.h>\n"));<br>
> -}<br>
> -<br>
> -// Tests includes in the middle of the code are ignored.<br>
> -TEST(IncludeDirectivesTest, ignoreHeadersMeantForMultipleInclusion) {<br>
> - std::string Expected = "#include \"foo.h\"\n"<br>
> - "#include <bar>\n"<br>
> - "\n"<br>
> - "enum Kind {\n"<br>
> - "#define X(A) K_##A,\n"<br>
> - "#include \"xmacro.def\"\n"<br>
> - "#undef X\n"<br>
> - " K_NUM_KINDS\n"<br>
> - "};\n";<br>
> - std::string Result = addIncludeInCode("bar", "#include \"foo.h\"\n"<br>
> - "\n"<br>
> - "enum Kind {\n"<br>
> - "#define X(A) K_##A,\n"<br>
> - "#include \"xmacro.def\"\n"<br>
> - "#undef X\n"<br>
> - " K_NUM_KINDS\n"<br>
> - "};\n");<br>
> - EXPECT_EQ(Expected, Result);<br>
> -}<br>
> -<br>
> -namespace {<br>
> -TestAddIncludeAction *makeIndirectTestsAction(const char *HeaderToModify,<br>
> - tooling::Replacements &Replaces) {<br>
> - StringRef IncludeToAdd = "c.h";<br>
> - TestAddIncludeAction *TestAction =<br>
> - new TestAddIncludeAction(IncludeToAdd, Replaces, HeaderToModify);<br>
> - TestAction->mapVirtualHeader("c.h", "#pragma once\n");<br>
> - TestAction->mapVirtualHeader("a.h", "#pragma once\n"<br>
> - "#include <c.h>\n");<br>
> - TestAction->mapVirtualHeader("b.h", "#pragma once\n");<br>
> - return TestAction;<br>
> -}<br>
> -} // end anonymous namespace<br>
> -<br>
> -TEST(IncludeDirectivesTest, indirectIncludes) {<br>
> - // In TestAddIncludeAction 'foo.h' includes 'foo-inner.h'. Check that we<br>
> - // aren't including foo-inner.h again.<br>
> - EXPECT_EQ("#include <foo.h>\n",<br>
> - addIncludeInCode("foo-inner.h", "#include <foo.h>\n"));<br>
> -<br>
> - tooling::Replacements Replaces;<br>
> - StringRef Code = "#include <a.h>\n"<br>
> - "#include <b.h>\n";<br>
> -<br>
> - // a.h already includes c.h<br>
> - {<br>
> - FrontendAction *Action = makeIndirectTestsAction("a.h", Replaces);<br>
> - ASSERT_NO_FATAL_FAILURE(applyActionOnCode(Action, Code));<br>
> - EXPECT_EQ(unsigned(0), Replaces.size());<br>
> - }<br>
> -<br>
> - // c.h is included before b.h but b.h doesn't include c.h directly, so check<br>
> - // that it will be inserted.<br>
> - {<br>
> - FrontendAction *Action = makeIndirectTestsAction("b.h", Replaces);<br>
> - ASSERT_NO_FATAL_FAILURE(applyActionOnCode(Action, Code));<br>
> - EXPECT_EQ("#include <c.h>\n\n\n",<br>
> - tooling::applyAllReplacements("\n", Replaces));<br>
> - }<br>
> -}<br>
> -<br>
> -/// \brief Convenience method to test header guards detection implementation.<br>
> -static std::string addIncludeInGuardedHeader(StringRef IncludeToAdd,<br>
> - StringRef GuardedHeaderCode) {<br>
> - const char *GuardedHeaderName = "guarded.h";<br>
> - tooling::Replacements Replaces;<br>
> - TestAddIncludeAction *TestAction =<br>
> - new TestAddIncludeAction(IncludeToAdd, Replaces, GuardedHeaderName);<br>
> - TestAction->mapVirtualHeader(GuardedHeaderName, GuardedHeaderCode);<br>
> -<br>
> - applyActionOnCode(TestAction, "#include <guarded.h>\n");<br>
> - if (::testing::Test::HasFailure())<br>
> - return "<<unexpected error from applyActionOnCode()>>";<br>
> -<br>
> - return tooling::applyAllReplacements(GuardedHeaderCode, Replaces);<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, insertInsideIncludeGuard) {<br>
> - EXPECT_EQ("#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#include <foo>\n"<br>
> - "\n"<br>
> - "struct foo {};\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n",<br>
> - addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo {};\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, guardAndHeader) {<br>
> - EXPECT_EQ("// File header\n"<br>
> - "\n"<br>
> - "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#include <foo>\n"<br>
> - "\n"<br>
> - "struct foo {};\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n",<br>
> - addIncludeInGuardedHeader("foo", "// File header\n"<br>
> - "\n"<br>
> - "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo {};\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, fullHeaderFitsAsAPreamble) {<br>
> - EXPECT_EQ("#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#include <foo>\n"<br>
> - "\n"<br>
> - "#define FOO 1\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n",<br>
> - addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#define FOO 1\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, codeBeforeIfndef) {<br>
> - EXPECT_EQ("#include <foo>\n"<br>
> - "\n"<br>
> - "int bar;\n"<br>
> - "\n"<br>
> - "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo;"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n",<br>
> - addIncludeInGuardedHeader("foo", "int bar;\n"<br>
> - "\n"<br>
> - "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo;"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, codeAfterEndif) {<br>
> - EXPECT_EQ("#include <foo>\n"<br>
> - "\n"<br>
> - "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo;"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"<br>
> - "\n"<br>
> - "int bar;\n",<br>
> - addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "struct foo;"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"<br>
> - "\n"<br>
> - "int bar;\n"));<br>
> -}<br>
> -<br>
> -TEST(IncludeDirectivesTest, headerGuardWithInclude) {<br>
> - EXPECT_EQ("#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#include <bar.h>\n"<br>
> - "#include <foo>\n"<br>
> - "\n"<br>
> - "struct foo;\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n",<br>
> - addIncludeInGuardedHeader("foo", "#ifndef GUARD_H\n"<br>
> - "#define GUARD_H\n"<br>
> - "\n"<br>
> - "#include <bar.h>\n"<br>
> - "\n"<br>
> - "struct foo;\n"<br>
> - "\n"<br>
> - "#endif // GUARD_H\n"));<br>
> -}<br>
> Index: unittests/clang-modernize/CMakeLists.txt<br>
> ===================================================================<br>
> --- unittests/clang-modernize/CMakeLists.txt<br>
> +++ /dev/null<br>
> @@ -1,33 +0,0 @@<br>
> -set(LLVM_LINK_COMPONENTS<br>
> - support<br>
> - )<br>
> -<br>
> -get_filename_component(CLANG_MODERNIZE_SOURCE_DIR<br>
> - ${CMAKE_CURRENT_SOURCE_DIR}/../../clang-modernize REALPATH)<br>
> -get_filename_component(ClangReplaceLocation<br>
> - "${CMAKE_CURRENT_SOURCE_DIR}/../../clang-apply-replacements/include" REALPATH)<br>
> -get_filename_component(CommonIncLocation<br>
> - "${CMAKE_CURRENT_SOURCE_DIR}/../include" REALPATH)<br>
> -include_directories(<br>
> - ${CLANG_MODERNIZE_SOURCE_DIR}<br>
> - ${ClangReplaceLocation}<br>
> - ${CommonIncLocation}<br>
> - )<br>
> -<br>
> -add_extra_unittest(ClangModernizeTests<br>
> - IncludeExcludeTest.cpp<br>
> - PerfSupportTest.cpp<br>
> - TransformTest.cpp<br>
> - UniqueHeaderNameTest.cpp<br>
> - IncludeDirectivesTest.cpp<br>
> - )<br>
> -<br>
> -target_link_libraries(ClangModernizeTests<br>
> - clangAST<br>
> - clangASTMatchers<br>
> - clangBasic<br>
> - clangFrontend<br>
> - clangTooling<br>
> - clangToolingCore<br>
> - modernizeCore<br>
> - )<br>
> Index: unittests/Makefile<br>
> ===================================================================<br>
> --- unittests/Makefile<br>
> +++ unittests/Makefile<br>
> @@ -10,6 +10,6 @@<br>
> CLANG_LEVEL := ../../..<br>
> include $(CLANG_LEVEL)/../../Makefile.config<br>
><br>
> -PARALLEL_DIRS := clang-apply-replacements clang-modernize clang-query clang-tidy clang-rename<br>
> +PARALLEL_DIRS := clang-apply-replacements clang-query clang-tidy clang-rename<br>
><br>
> include $(CLANG_LEVEL)/Makefile<br>
> Index: unittests/CMakeLists.txt<br>
> ===================================================================<br>
> --- unittests/CMakeLists.txt<br>
> +++ unittests/CMakeLists.txt<br>
> @@ -6,7 +6,6 @@<br>
> endfunction()<br>
><br>
> add_subdirectory(clang-apply-replacements)<br>
> -add_subdirectory(clang-modernize)<br>
> add_subdirectory(clang-rename)<br>
> add_subdirectory(clang-query)<br>
> add_subdirectory(clang-tidy)<br>
> Index: test/clang-modernize/UseNullptr/nullptr_t.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseNullptr/nullptr_t.cpp<br>
> +++ /dev/null<br>
> @@ -1,29 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -final-syntax-check -use-nullptr %t.cpp -- --std=c++11 -I %S<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -namespace std {<br>
> -<br>
> -typedef decltype(nullptr) nullptr_t;<br>
> -<br>
> -} // namespace std<br>
> -<br>
> -// Just to make sure make_null() could have side effects.<br>
> -void external();<br>
> -<br>
> -std::nullptr_t make_null() {<br>
> - external();<br>
> - return nullptr;<br>
> -}<br>
> -<br>
> -void func() {<br>
> - void *CallTest = make_null();<br>
> - // CHECK: void *CallTest = make_null();<br>
> -<br>
> - int var = 1;<br>
> - void *CommaTest = (var+=2, make_null());<br>
> - // CHECK: void *CommaTest = (var+=2, make_null());<br>
> -<br>
> - int *CastTest = static_cast<int*>(make_null());<br>
> - // CHECK: int *CastTest = static_cast<int*>(make_null());<br>
> -}<br>
> Index: test/clang-modernize/UseNullptr/macros.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseNullptr/macros.cpp<br>
> +++ /dev/null<br>
> @@ -1,164 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-nullptr %t.cpp -- -I %S<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp<br>
> -// RUN: clang-modernize -use-nullptr -user-null-macros=MY_NULL %t2.cpp -- -I %S<br>
> -// RUN: FileCheck -check-prefix=USER-SUPPLIED-NULL -input-file=%t2.cpp %s<br>
> -<br>
> -#define NULL 0<br>
> -// CHECK: #define NULL 0<br>
> -<br>
> -void dummy(int*) {}<br>
> -void side_effect() {}<br>
> -<br>
> -#define MACRO_EXPANSION_HAS_NULL \<br>
> - void foo() { \<br>
> - dummy(0); \<br>
> - dummy(NULL); \<br>
> - side_effect(); \<br>
> - }<br>
> - // CHECK: void foo() { \<br>
> - // CHECK-NEXT: dummy(0); \<br>
> - // CHECK-NEXT: dummy(NULL); \<br>
> -<br>
> -MACRO_EXPANSION_HAS_NULL;<br>
> -// CHECK: MACRO_EXPANSION_HAS_NULL;<br>
> -#undef MACRO_EXPANSION_HAS_NULL<br>
> -<br>
> -<br>
> -void test_macro_expansion1() {<br>
> -#define MACRO_EXPANSION_HAS_NULL \<br>
> - dummy(NULL); \<br>
> - side_effect();<br>
> - // CHECK: dummy(NULL); \<br>
> - // CHECK-NEXT: side_effect();<br>
> -<br>
> - MACRO_EXPANSION_HAS_NULL;<br>
> - // CHECK: MACRO_EXPANSION_HAS_NULL;<br>
> -<br>
> -#undef MACRO_EXPANSION_HAS_NULL<br>
> -}<br>
> -<br>
> -// Test macro expansion with cast sequence, PR15572<br>
> -void test_macro_expansion2() {<br>
> -#define MACRO_EXPANSION_HAS_NULL \<br>
> - dummy((int*)0); \<br>
> - side_effect();<br>
> - // CHECK: dummy((int*)0); \<br>
> - // CHECK-NEXT: side_effect();<br>
> -<br>
> - MACRO_EXPANSION_HAS_NULL;<br>
> - // CHECK: MACRO_EXPANSION_HAS_NULL;<br>
> -<br>
> -#undef MACRO_EXPANSION_HAS_NULL<br>
> -}<br>
> -<br>
> -void test_macro_expansion3() {<br>
> -#define MACRO_EXPANSION_HAS_NULL \<br>
> - dummy(NULL); \<br>
> - side_effect();<br>
> - // CHECK: dummy(NULL); \<br>
> - // CHECK-NEXT: side_effect();<br>
> -<br>
> -#define OUTER_MACRO \<br>
> - MACRO_EXPANSION_HAS_NULL; \<br>
> - side_effect();<br>
> -<br>
> - OUTER_MACRO;<br>
> - // CHECK: OUTER_MACRO;<br>
> -<br>
> -#undef OUTER_MACRO<br>
> -#undef MACRO_EXPANSION_HAS_NULL<br>
> -}<br>
> -<br>
> -void test_macro_expansion4() {<br>
> -#define MY_NULL NULL<br>
> - int *p = MY_NULL;<br>
> - // CHECK: int *p = MY_NULL;<br>
> - // USER-SUPPLIED-NULL: int *p = nullptr;<br>
> -#undef MY_NULL<br>
> -}<br>
> -<br>
> -#define IS_EQ(x, y) if (x != y) return;<br>
> -void test_macro_args() {<br>
> - int i = 0;<br>
> - int *Ptr;<br>
> -<br>
> - IS_EQ(static_cast<int*>(0), Ptr);<br>
> - // CHECK: IS_EQ(static_cast<int*>(nullptr), Ptr);<br>
> - IS_EQ(0, Ptr); // literal<br>
> - // CHECK: IS_EQ(nullptr, Ptr);<br>
> - IS_EQ(NULL, Ptr); // macro<br>
> - // CHECK: IS_EQ(nullptr, Ptr);<br>
> -<br>
> - // These are ok since the null literal is not spelled within a macro.<br>
> -#define myassert(x) if (!(x)) return;<br>
> - myassert(0 == Ptr);<br>
> - // CHECK: myassert(nullptr == Ptr);<br>
> - myassert(NULL == Ptr);<br>
> - // CHECK: myassert(nullptr == Ptr);<br>
> -<br>
> - // These are bad as the null literal is buried in a macro.<br>
> -#define BLAH(X) myassert(0 == (X));<br>
> - // CHECK: #define BLAH(X) myassert(0 == (X));<br>
> -#define BLAH2(X) myassert(NULL == (X));<br>
> - // CHECK: #define BLAH2(X) myassert(NULL == (X));<br>
> - BLAH(Ptr);<br>
> - // CHECK: BLAH(Ptr);<br>
> - BLAH2(Ptr);<br>
> - // CHECK: BLAH2(Ptr);<br>
> -<br>
> - // Same as above but testing extra macro expansion.<br>
> -#define EXPECT_NULL(X) IS_EQ(0, X);<br>
> - // CHECK: #define EXPECT_NULL(X) IS_EQ(0, X);<br>
> -#define EXPECT_NULL2(X) IS_EQ(NULL, X);<br>
> - // CHECK: #define EXPECT_NULL2(X) IS_EQ(NULL, X);<br>
> - EXPECT_NULL(Ptr);<br>
> - // CHECK: EXPECT_NULL(Ptr);<br>
> - EXPECT_NULL2(Ptr);<br>
> - // CHECK: EXPECT_NULL2(Ptr);<br>
> -<br>
> - // Almost the same as above but now null literal is not in a macro so ok<br>
> - // to transform.<br>
> -#define EQUALS_PTR(X) IS_EQ(X, Ptr);<br>
> - EQUALS_PTR(0);<br>
> - EQUALS_PTR(NULL);<br>
> -<br>
> - // Same as above but testing extra macro expansion.<br>
> -#define EQUALS_PTR_I(X) EQUALS_PTR(X)<br>
> - EQUALS_PTR_I(0);<br>
> - // CHECK: EQUALS_PTR_I(nullptr);<br>
> - EQUALS_PTR_I(NULL);<br>
> - // CHECK: EQUALS_PTR_I(nullptr);<br>
> -<br>
> - // Ok since null literal not within macro. However, now testing macro<br>
> - // used as arg to another macro.<br>
> -#define decorate(EXPR) side_effect(); EXPR;<br>
> - decorate(IS_EQ(NULL, Ptr));<br>
> - // CHECK: decorate(IS_EQ(nullptr, Ptr));<br>
> - decorate(IS_EQ(0, Ptr));<br>
> - // CHECK: decorate(IS_EQ(nullptr, Ptr));<br>
> -<br>
> - // This macro causes a NullToPointer cast to happen where 0 is assigned to z<br>
> - // but the 0 literal cannot be replaced because it is also used as an<br>
> - // integer in the comparison.<br>
> -#define INT_AND_PTR_USE(X) do { int *z = X; if (X == 4) break; } while(false)<br>
> - INT_AND_PTR_USE(0);<br>
> - // CHECK: INT_AND_PTR_USE(0);<br>
> -<br>
> - // Both uses of X in this case result in NullToPointer casts so replacement<br>
> - // is possible.<br>
> -#define PTR_AND_PTR_USE(X) do { int *z = X; if (X != z) break; } while(false)<br>
> - PTR_AND_PTR_USE(0);<br>
> - // CHECK: PTR_AND_PTR_USE(nullptr);<br>
> - PTR_AND_PTR_USE(NULL);<br>
> - // CHECK: PTR_AND_PTR_USE(nullptr);<br>
> -<br>
> -#define OPTIONAL_CODE(...) __VA_ARGS__<br>
> -#define NOT_NULL dummy(0)<br>
> -#define CALL(X) X<br>
> - OPTIONAL_CODE(NOT_NULL);<br>
> - // CHECK: OPTIONAL_CODE(NOT_NULL);<br>
> - CALL(NOT_NULL);<br>
> - // CHECK: CALL(NOT_NULL);<br>
> -}<br>
> Index: test/clang-modernize/UseNullptr/basic_failing.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseNullptr/basic_failing.cpp<br>
> +++ /dev/null<br>
> @@ -1,27 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-nullptr %t.cpp -- -I %S<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// XFAIL: *<br>
> -<br>
> -#define NULL 0<br>
> -<br>
> -template <typename T><br>
> -class A {<br>
> -public:<br>
> - A(T *p = NULL) {}<br>
> - // CHECK: A(T *p = nullptr) {}<br>
> -<br>
> - void f() {<br>
> - Ptr = NULL;<br>
> - // CHECK: Ptr = nullptr;<br>
> - }<br>
> -<br>
> - T *Ptr;<br>
> -};<br>
> -<br>
> -template <typename T><br>
> -T *f2(T *a = NULL) {<br>
> - // CHECK: T *f2(T *a = nullptr) {<br>
> - return a ? a : NULL;<br>
> - // CHECK: return a ? a : nullptr;<br>
> -}<br>
> Index: test/clang-modernize/UseNullptr/basic.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseNullptr/basic.cpp<br>
> +++ /dev/null<br>
> @@ -1,291 +0,0 @@<br>
> -// RUN: mkdir -p %T/Inputs<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h<br>
> -// RUN: clang-modernize -use-nullptr -include=%T %t.cpp -- -std=c++98 -I %T -Wno-non-literal-null-conversion<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h<br>
> -<br>
> -#include "Inputs/basic.h"<br>
> -<br>
> -const unsigned int g_null = 0;<br>
> -#define NULL 0<br>
> -// CHECK: #define NULL 0<br>
> -<br>
> -void test_assignment() {<br>
> - int *p1 = 0;<br>
> - // CHECK: int *p1 = nullptr;<br>
> - p1 = 0;<br>
> - // CHECK: p1 = nullptr;<br>
> -<br>
> - int *p2 = NULL;<br>
> - // CHECK: int *p2 = nullptr;<br>
> -<br>
> - p2 = p1;<br>
> - // CHECK: p2 = p1;<br>
> -<br>
> - const int null = 0;<br>
> - int *p3 = null;<br>
> - // CHECK: int *p3 = nullptr;<br>
> -<br>
> - p3 = NULL;<br>
> - // CHECK: p3 = nullptr;<br>
> -<br>
> - int *p4 = p3;<br>
> - // CHECK: int *p4 = p3;<br>
> -<br>
> - p4 = null;<br>
> - // CHECK: p4 = nullptr;<br>
> -<br>
> - int i1 = 0;<br>
> - // CHECK: int i1 = 0;<br>
> -<br>
> - int i2 = NULL;<br>
> - // CHECK: int i2 = NULL;<br>
> -<br>
> - int i3 = null;<br>
> - // CHECK: int i3 = null;<br>
> -<br>
> - int *p5, *p6, *p7;<br>
> - p5 = p6 = p7 = NULL;<br>
> - // CHECK: p5 = p6 = p7 = nullptr;<br>
> -}<br>
> -<br>
> -struct Foo {<br>
> - Foo(int *p = NULL) : m_p1(p) {}<br>
> - // CHECK: Foo(int *p = nullptr) : m_p1(p) {}<br>
> -<br>
> - void bar(int *p = 0) {}<br>
> - // CHECK: void bar(int *p = nullptr) {}<br>
> -<br>
> - void baz(int i = 0) {}<br>
> - // CHECK: void baz(int i = 0) {}<br>
> -<br>
> - int *m_p1;<br>
> - static int *m_p2;<br>
> -};<br>
> -<br>
> -int *Foo::m_p2 = NULL;<br>
> -// CHECK: int *Foo::m_p2 = nullptr;<br>
> -<br>
> -template <typename T><br>
> -struct Bar {<br>
> - Bar(T *p) : m_p(p) {<br>
> - m_p = static_cast<T*>(NULL);<br>
> - // CHECK: m_p = static_cast<T*>(nullptr);<br>
> -<br>
> - m_p = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));<br>
> - // CHECK: m_p = static_cast<T*>(nullptr);<br>
> -<br>
> - m_p = static_cast<T*>(p ? p : static_cast<void*>(g_null));<br>
> - // CHECK: m_p = static_cast<T*>(p ? p : static_cast<void*>(nullptr));<br>
> -<br>
> - T *p2 = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));<br>
> - // CHECK: T *p2 = static_cast<T*>(nullptr);<br>
> -<br>
> - m_p = NULL;<br>
> - // CHECK: m_p = nullptr;<br>
> -<br>
> - int i = static_cast<int>(0.f);<br>
> - // CHECK: int i = static_cast<int>(0.f);<br>
> - T *i2 = static_cast<int>(0.f);<br>
> - // CHECK: T *i2 = nullptr;<br>
> - }<br>
> -<br>
> - T *m_p;<br>
> -};<br>
> -<br>
> -struct Baz {<br>
> - Baz() : i(0) {}<br>
> - int i;<br>
> -};<br>
> -<br>
> -void test_cxx_cases() {<br>
> - Foo f(g_null);<br>
> - // CHECK: Foo f(nullptr);<br>
> -<br>
> - f.bar(NULL);<br>
> - // CHECK: f.bar(nullptr);<br>
> -<br>
> - f.baz(g_null);<br>
> - // CHECK: f.baz(g_null);<br>
> -<br>
> - f.m_p1 = 0;<br>
> - // CHECK: f.m_p1 = nullptr;<br>
> -<br>
> - Bar<int> b(g_null);<br>
> - // CHECK: Bar<int> b(nullptr);<br>
> -<br>
> - Baz b2;<br>
> - int Baz::*memptr(0);<br>
> - // CHECK: int Baz::*memptr(nullptr);<br>
> -<br>
> - memptr = 0;<br>
> - // CHECK: memptr = nullptr;<br>
> -}<br>
> -<br>
> -void test_function_default_param1(void *p = 0);<br>
> -// CHECK: void test_function_default_param1(void *p = nullptr);<br>
> -<br>
> -void test_function_default_param2(void *p = NULL);<br>
> -// CHECK: void test_function_default_param2(void *p = nullptr);<br>
> -<br>
> -void test_function_default_param3(void *p = g_null);<br>
> -// CHECK: void test_function_default_param3(void *p = nullptr);<br>
> -<br>
> -void test_function(int *p) {}<br>
> -// CHECK: void test_function(int *p) {}<br>
> -<br>
> -void test_function_no_ptr_param(int i) {}<br>
> -<br>
> -void test_function_call() {<br>
> - test_function(0);<br>
> - // CHECK: test_function(nullptr);<br>
> -<br>
> - test_function(NULL);<br>
> - // CHECK: test_function(nullptr);<br>
> -<br>
> - test_function(g_null);<br>
> - // CHECK: test_function(nullptr);<br>
> -<br>
> - test_function_no_ptr_param(0);<br>
> - // CHECK: test_function_no_ptr_param(0);<br>
> -}<br>
> -<br>
> -char *test_function_return1() {<br>
> - return 0;<br>
> - // CHECK: return nullptr;<br>
> -}<br>
> -<br>
> -void *test_function_return2() {<br>
> - return NULL;<br>
> - // CHECK: return nullptr;<br>
> -}<br>
> -<br>
> -long *test_function_return3() {<br>
> - return g_null;<br>
> - // CHECK: return nullptr;<br>
> -}<br>
> -<br>
> -int test_function_return4() {<br>
> - return 0;<br>
> - // CHECK: return 0;<br>
> -}<br>
> -<br>
> -int test_function_return5() {<br>
> - return NULL;<br>
> - // CHECK: return NULL;<br>
> -}<br>
> -<br>
> -int test_function_return6() {<br>
> - return g_null;<br>
> - // CHECK: return g_null;<br>
> -}<br>
> -<br>
> -int *test_function_return_cast1() {<br>
> - return(int)0;<br>
> - // CHECK: return nullptr;<br>
> -}<br>
> -<br>
> -int *test_function_return_cast2() {<br>
> - #define RET return<br>
> - RET(int)0;<br>
> - // CHECK: RET nullptr;<br>
> - #undef RET<br>
> -}<br>
> -<br>
> -// Test parentheses expressions resulting in a nullptr.<br>
> -int *test_parentheses_expression1() {<br>
> - return(0);<br>
> - // CHECK: return(nullptr);<br>
> -}<br>
> -<br>
> -int *test_parentheses_expression2() {<br>
> - return(int(0.f));<br>
> - // CHECK: return(nullptr);<br>
> -}<br>
> -<br>
> -int *test_nested_parentheses_expression() {<br>
> - return((((0))));<br>
> - // CHECK: return((((nullptr))));<br>
> -}<br>
> -<br>
> -void *test_parentheses_explicit_cast() {<br>
> - return(static_cast<void*>(0));<br>
> - // CHECK: return(static_cast<void*>(nullptr));<br>
> -}<br>
> -<br>
> -void *test_parentheses_explicit_cast_sequence1() {<br>
> - return(static_cast<void*>(static_cast<int*>((void*)NULL)));<br>
> - // CHECK: return(static_cast<void*>(nullptr));<br>
> -}<br>
> -<br>
> -void *test_parentheses_explicit_cast_sequence2() {<br>
> - return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));<br>
> - // CHECK: return(static_cast<void*>(nullptr));<br>
> -}<br>
> -<br>
> -// Test explicit cast expressions resulting in nullptr<br>
> -struct Bam {<br>
> - Bam(int *a) {}<br>
> - Bam(float *a) {}<br>
> - Bam operator=(int *a) { return Bam(a); }<br>
> - Bam operator=(float *a) { return Bam(a); }<br>
> -};<br>
> -<br>
> -void ambiguous_function(int *a) {}<br>
> -void ambiguous_function(float *a) {}<br>
> -void const_ambiguous_function(const int *p) {}<br>
> -void const_ambiguous_function(const float *p) {}<br>
> -<br>
> -void test_explicit_cast_ambiguous1() {<br>
> - ambiguous_function((int*)0);<br>
> - // CHECK: ambiguous_function((int*)nullptr);<br>
> -}<br>
> -<br>
> -void test_explicit_cast_ambiguous2() {<br>
> - ambiguous_function((int*)(0));<br>
> - // CHECK: ambiguous_function((int*)nullptr);<br>
> -}<br>
> -<br>
> -void test_explicit_cast_ambiguous3() {<br>
> - ambiguous_function(static_cast<int*>(reinterpret_cast<int*>((float*)0)));<br>
> - // CHECK: ambiguous_function(static_cast<int*>(nullptr));<br>
> -}<br>
> -<br>
> -Bam test_explicit_cast_ambiguous4() {<br>
> - return(((int*)(0)));<br>
> - // CHECK: return(((int*)nullptr));<br>
> -}<br>
> -<br>
> -void test_explicit_cast_ambiguous5() {<br>
> - // Test for ambiguous overloaded constructors<br>
> - Bam k((int*)(0));<br>
> - // CHECK: Bam k((int*)nullptr);<br>
> -<br>
> - // Test for ambiguous overloaded operators<br>
> - k = (int*)0;<br>
> - // CHECK: k = (int*)nullptr;<br>
> -}<br>
> -<br>
> -void test_const_pointers_abiguous() {<br>
> - const_ambiguous_function((int*)0);<br>
> - // CHECK: const_ambiguous_function((int*)nullptr);<br>
> -}<br>
> -<br>
> -// Test where the implicit cast to null is surrounded by another implict cast<br>
> -// with possible explict casts in-between.<br>
> -void test_const_pointers() {<br>
> - const int *const_p1 = 0;<br>
> - // CHECK: const int *const_p1 = nullptr;<br>
> - const int *const_p2 = NULL;<br>
> - // CHECK: const int *const_p2 = nullptr;<br>
> - const int *const_p3 = (int)0;<br>
> - // CHECK: const int *const_p3 = nullptr;<br>
> - const int *const_p4 = (int)0.0f;<br>
> - // CHECK: const int *const_p4 = nullptr;<br>
> - const int *const_p5 = (int*)0;<br>
> - // CHECK: const int *const_p5 = (int*)nullptr;<br>
> - int *t;<br>
> - const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(0));<br>
> - // CHECK: const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));<br>
> -}<br>
> Index: test/clang-modernize/UseNullptr/Inputs/basic.h<br>
> ===================================================================<br>
> --- test/clang-modernize/UseNullptr/Inputs/basic.h<br>
> +++ /dev/null<br>
> @@ -1,2 +0,0 @@<br>
> -int *global_p = 0;<br>
> -// CHECK: int *global_p = nullptr;<br>
> Index: test/clang-modernize/UseAuto/new_cv_failing.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseAuto/new_cv_failing.cpp<br>
> +++ /dev/null<br>
> @@ -1,36 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -std=c++11<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// XFAIL: *<br>
> -<br>
> -// None of these tests can pass right now because TypeLoc information where CV<br>
> -// qualifiers are concerned is not reliable/available.<br>
> -<br>
> -class MyType {<br>
> -};<br>
> -<br>
> -int main (int argc, char **argv) {<br>
> - const MyType *d = new MyType();<br>
> - // CHECK: const auto *d = new MyType();<br>
> -<br>
> - volatile MyType *d2 = new MyType();<br>
> - // CHECK: volatile auto *d2 = new MyType();<br>
> -<br>
> - const MyType * volatile e = new MyType();<br>
> - // CHECK: const auto * volatile d = new MyType();<br>
> -<br>
> - volatile MyType * const f = new MyType();<br>
> - // CHECK: volatile auto * const d2 = new MyType();<br>
> -<br>
> - const MyType *d5 = new const MyType();<br>
> - // CHECK: auto d5 = new const MyType();<br>
> -<br>
> - volatile MyType *d6 = new volatile MyType();<br>
> - // CHECK: auto d6 = new volatile MyType();<br>
> -<br>
> - const MyType * const d7 = new const MyType();<br>
> - // CHECK: const auto d7 = new const MyType();<br>
> -<br>
> - volatile MyType * volatile d8 = new volatile MyType();<br>
> - // CHECK: volatile auto d8 = new volatile MyType();<br>
> -}<br>
> Index: test/clang-modernize/UseAuto/new.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseAuto/new.cpp<br>
> +++ /dev/null<br>
> @@ -1,97 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -std=c++11<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -class MyType {<br>
> -};<br>
> -<br>
> -class MyDerivedType : public MyType {<br>
> -};<br>
> -<br>
> -int main(int argc, char **argv) {<br>
> - MyType *a = new MyType();<br>
> - // CHECK: auto a = new MyType();<br>
> -<br>
> - static MyType *a_static = new MyType();<br>
> - // CHECK: static auto a_static = new MyType();<br>
> -<br>
> - MyType *b = new MyDerivedType();<br>
> - // CHECK: MyType *b = new MyDerivedType();<br>
> -<br>
> - void *c = new MyType();<br>
> - // CHECK: void *c = new MyType();<br>
> -<br>
> - // CV-qualifier tests.<br>
> - //<br>
> - // NOTE : the form "type const" is expected here because of a deficiency in<br>
> - // TypeLoc where CV qualifiers are not considered part of the type location<br>
> - // info. That is, all that is being replaced in each case is "MyType *" and<br>
> - // not "MyType * const".<br>
> - {<br>
> - static MyType * const d_static = new MyType();<br>
> - // CHECK: static auto const d_static = new MyType();<br>
> -<br>
> - MyType * const d3 = new MyType();<br>
> - // CHECK: auto const d3 = new MyType();<br>
> -<br>
> - MyType * volatile d4 = new MyType();<br>
> - // CHECK: auto volatile d4 = new MyType();<br>
> - }<br>
> -<br>
> - int (**func)(int, int) = new (int(*[5])(int,int));<br>
> - // CHECK: int (**func)(int, int) = new (int(*[5])(int,int));<br>
> -<br>
> - int *e = new int[5];<br>
> - // CHECK: auto e = new int[5];<br>
> -<br>
> - MyType *f(new MyType);<br>
> - // CHECK: auto f(new MyType);<br>
> -<br>
> - MyType *g{new MyType};<br>
> - // CHECK: MyType *g{new MyType};<br>
> -<br>
> - // Test for declaration lists.<br>
> - {<br>
> - MyType *a = new MyType(), *b = new MyType(), *c = new MyType();<br>
> - // CHECK: auto a = new MyType(), b = new MyType(), c = new MyType();<br>
> -<br>
> - // Non-initialized declaration should not be transformed.<br>
> - MyType *d = new MyType(), *e;<br>
> - // CHECK: MyType *d = new MyType(), *e;<br>
> -<br>
> - MyType **f = new MyType*(), **g = new MyType*();<br>
> - // CHECK: auto f = new MyType*(), g = new MyType*();<br>
> -<br>
> - // Mismatching types in declaration lists should not be transformed.<br>
> - MyType *h = new MyType(), **i = new MyType*();<br>
> - // CHECK: MyType *h = new MyType(), **i = new MyType*();<br>
> -<br>
> - // '*' shouldn't be removed in case of mismatching types with multiple<br>
> - // declarations.<br>
> - MyType *j = new MyType(), *k = new MyType(), **l = new MyType*();<br>
> - // CHECK: MyType *j = new MyType(), *k = new MyType(), **l = new MyType*();<br>
> - }<br>
> -<br>
> - // Test for typedefs.<br>
> - {<br>
> - typedef int * int_p;<br>
> -<br>
> - int_p a = new int;<br>
> - // CHECK: auto a = new int;<br>
> - int_p *b = new int*;<br>
> - // CHECK: auto b = new int*;<br>
> -<br>
> - // Test for typedefs in declarations lists.<br>
> - int_p c = new int, d = new int;<br>
> - // CHECK: auto c = new int, d = new int;<br>
> -<br>
> - // Different types should not be transformed.<br>
> - int_p e = new int, *f = new int_p;<br>
> - // CHECK: int_p e = new int, *f = new int_p;<br>
> -<br>
> - int_p *g = new int*, *h = new int_p;<br>
> - // CHECK: auto g = new int*, h = new int_p;<br>
> - }<br>
> -<br>
> - return 0;<br>
> -}<br>
> Index: test/clang-modernize/UseAuto/iterator.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseAuto/iterator.cpp<br>
> +++ /dev/null<br>
> @@ -1,178 +0,0 @@<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- --std=c++11 -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- --std=c++11 -I %S/Inputs \<br>
> -// RUN: -DUSE_INLINE_NAMESPACE=1<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -<br>
> -#define CONTAINER array<br>
> -#include "test_std_container.h"<br>
> -#undef CONTAINER<br>
> -<br>
> -#define CONTAINER vector<br>
> -#include "test_std_container.h"<br>
> -#undef CONTAINER<br>
> -<br>
> -#define CONTAINER unordered_map<br>
> -#define USE_BASE_CLASS_ITERATORS 1<br>
> -#include "test_std_container.h"<br>
> -#undef USE_BASE_CLASS_ITERATORS<br>
> -#undef CONTAINER<br>
> -<br>
> -typedef std::vector<int>::iterator int_iterator;<br>
> -<br>
> -namespace foo {<br>
> - template <typename T><br>
> - class vector {<br>
> - public:<br>
> - class iterator {};<br>
> -<br>
> - iterator begin() { return iterator(); }<br>
> - };<br>
> -} // namespace foo<br>
> -<br>
> -int main(int argc, char **argv) {<br>
> - std::vector<int> Vec;<br>
> - // CHECK: std::vector<int> Vec;<br>
> -<br>
> - std::unordered_map<int> Map;<br>
> - // CHECK: std::unordered_map<int> Map;<br>
> -<br>
> - // Types with more sugar should work. Types with less should not.<br>
> - {<br>
> - int_iterator more_sugar = Vec.begin();<br>
> - // CHECK: auto more_sugar = Vec.begin();<br>
> -<br>
> - internal::iterator_wrapper<std::vector<int>, 0> less_sugar = Vec.begin();<br>
> - // CHECK: internal::iterator_wrapper<std::vector<int>, 0> less_sugar = Vec.begin();<br>
> - }<br>
> -<br>
> - // Initialization from initializer lists isn't allowed. Using 'auto'<br>
> - // would result in std::initializer_list being deduced for the type.<br>
> - {<br>
> - std::unordered_map<int>::iterator I{Map.begin()};<br>
> - // CHECK: std::unordered_map<int>::iterator I{Map.begin()};<br>
> -<br>
> - std::unordered_map<int>::iterator I2 = {Map.begin()};<br>
> - // CHECK: std::unordered_map<int>::iterator I2 = {Map.begin()};<br>
> - }<br>
> -<br>
> - // Various forms of construction. Default constructors and constructors with<br>
> - // all-default parameters shouldn't get transformed. Construction from other<br>
> - // types is also not allowed.<br>
> - {<br>
> - std::unordered_map<int>::iterator copy(Map.begin());<br>
> - // CHECK: auto copy(Map.begin());<br>
> -<br>
> - std::unordered_map<int>::iterator def;<br>
> - // CHECK: std::unordered_map<int>::iterator def;<br>
> -<br>
> - // const_iterator has no default constructor, just one that has >0 params<br>
> - // with defaults.<br>
> - std::unordered_map<int>::const_iterator constI;<br>
> - // CHECK: std::unordered_map<int>::const_iterator constI;<br>
> -<br>
> - // Uses iterator_provider::const_iterator's conversion constructor.<br>
> -<br>
> - std::unordered_map<int>::const_iterator constI2 = def;<br>
> - // CHECK: std::unordered_map<int>::const_iterator constI2 = def;<br>
> -<br>
> - std::unordered_map<int>::const_iterator constI3(def);<br>
> - // CHECK: std::unordered_map<int>::const_iterator constI3(def);<br>
> -<br>
> - // Explicit use of conversion constructor<br>
> -<br>
> - std::unordered_map<int>::const_iterator constI4 = std::unordered_map<int>::const_iterator(def);<br>
> - // CHECK: auto constI4 = std::unordered_map<int>::const_iterator(def);<br>
> -<br>
> - // Uses iterator_provider::iterator's const_iterator conversion operator.<br>
> -<br>
> - std::unordered_map<int>::iterator I = constI;<br>
> - // CHECK: std::unordered_map<int>::iterator I = constI;<br>
> -<br>
> - std::unordered_map<int>::iterator I2(constI);<br>
> - // CHECK: std::unordered_map<int>::iterator I2(constI);<br>
> - }<br>
> -<br>
> - // Weird cases of pointers and references to iterators are not transformed.<br>
> - {<br>
> - int_iterator I = Vec.begin();<br>
> -<br>
> - int_iterator *IPtr = &I;<br>
> - // CHECK: int_iterator *IPtr = &I;<br>
> -<br>
> - int_iterator &IRef = I;<br>
> - // CHECK: int_iterator &IRef = I;<br>
> - }<br>
> -<br>
> - {<br>
> - // Variable declarations in iteration statements.<br>
> - for (std::vector<int>::iterator I = Vec.begin(); I != Vec.end(); ++I) {<br>
> - // CHECK: for (auto I = Vec.begin(); I != Vec.end(); ++I) {<br>
> - }<br>
> -<br>
> - // Range-based for loops.<br>
> - std::array<std::vector<int>::iterator> iter_arr;<br>
> - for (std::vector<int>::iterator I: iter_arr) {<br>
> - // CHECK: for (auto I: iter_arr) {<br>
> - }<br>
> -<br>
> - // Test with init-declarator-list.<br>
> - for (int_iterator I = Vec.begin(),<br>
> - E = Vec.end(); I != E; ++I) {<br>
> - // CHECK: for (auto I = Vec.begin(),<br>
> - // CHECK-NEXT: E = Vec.end(); I != E; ++I) {<br>
> - }<br>
> - }<br>
> -<br>
> - // Only std containers should be changed.<br>
> - {<br>
> - using namespace foo;<br>
> - vector<int> foo_vec;<br>
> - vector<int>::iterator I = foo_vec.begin();<br>
> - // CHECK: vector<int>::iterator I = foo_vec.begin();<br>
> - }<br>
> -<br>
> - // Ensure using directives don't interfere with replacement.<br>
> - {<br>
> - using namespace std;<br>
> - vector<int> std_vec;<br>
> - vector<int>::iterator I = std_vec.begin();<br>
> - // CHECK: auto I = std_vec.begin();<br>
> - }<br>
> -<br>
> - // Make sure references and cv qualifiers don't get removed (i.e. replaced<br>
> - // with just 'auto').<br>
> - {<br>
> - const auto & I = Vec.begin();<br>
> - // CHECK: const auto & I = Vec.begin();<br>
> -<br>
> - auto && I2 = Vec.begin();<br>
> - // CHECK: auto && I2 = Vec.begin();<br>
> - }<br>
> -<br>
> - // Passing a string as an argument to introduce a temporary object<br>
> - // that will create an expression with cleanups. Bugzilla: 15550<br>
> - {<br>
> - std::unordered_map<int> MapFind;<br>
> - std::unordered_map<int>::iterator I = MapFind.find("foo");<br>
> - // CHECK: auto I = MapFind.find("foo");<br>
> - }<br>
> -<br>
> - // Test for declaration lists<br>
> - {<br>
> - // Ensusre declaration lists that matches the declaration type with written<br>
> - // no-list initializer are transformed.<br>
> - std::vector<int>::iterator I = Vec.begin(), E = Vec.end();<br>
> - // CHECK: auto I = Vec.begin(), E = Vec.end();<br>
> -<br>
> - // Declaration lists with non-initialized variables should not be<br>
> - // transformed.<br>
> - std::vector<int>::iterator J = Vec.begin(), K;<br>
> - // CHECK: std::vector<int>::iterator J = Vec.begin(), K;<br>
> - }<br>
> - return 0;<br>
> -}<br>
> Index: test/clang-modernize/UseAuto/basic_iterator_tests.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/UseAuto/basic_iterator_tests.cpp<br>
> +++ /dev/null<br>
> @@ -1,123 +0,0 @@<br>
> -// This file contains basic positive tests for the use-auto transform's ability<br>
> -// to replace standard iterators. Variables considered:<br>
> -// * All std container names<br>
> -// * All std iterator names<br>
> -// * Different patterns of defining iterators and containers<br>
> -//<br>
> -// // The most basic test.<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=array -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -//<br>
> -// Test variations on how the container and its iterators might be defined.<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=array \<br>
> -// RUN: -DUSE_INLINE_NAMESPACE=1 -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=array \<br>
> -// RUN: -DUSE_BASE_CLASS_ITERATORS=1 -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=array \<br>
> -// RUN: -DUSE_INNER_CLASS_ITERATORS=1 -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -//<br>
> -// Test all of the other container names in a basic configuration.<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=deque -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=forward_list -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=list -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=vector -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=map -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=multimap -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=set -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=multiset -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=unordered_map -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=unordered_multimap -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=unordered_set -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=unordered_multiset -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=queue -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=priority_queue -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -use-auto %t.cpp -- -DCONTAINER=stack -I %S/Inputs<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -#ifndef CONTAINER<br>
> -#error You must define CONTAINER to the name of the container for testing.<br>
> -#endif<br>
> -<br>
> -#include "test_std_container.h"<br>
> -<br>
> -int main(int argc, char **argv) {<br>
> - {<br>
> - std::CONTAINER<int> C;<br>
> - std::CONTAINER<int>::iterator I = C.begin();<br>
> - // CHECK: auto I = C.begin();<br>
> - }<br>
> - {<br>
> - std::CONTAINER<int> C;<br>
> - std::CONTAINER<int>::reverse_iterator I = C.rbegin();<br>
> - // CHECK: auto I = C.rbegin();<br>
> - }<br>
> - {<br>
> - const std::CONTAINER<int> C;<br>
> - std::CONTAINER<int>::const_iterator I = C.begin();<br>
> - // CHECK: auto I = C.begin();<br>
> - }<br>
> - {<br>
> - const std::CONTAINER<int> C;<br>
> - std::CONTAINER<int>::const_reverse_iterator I = C.rbegin();<br>
> - // CHECK: auto I = C.rbegin();<br>
> - }<br>
> -<br>
> - return 0;<br>
> -}<br>
> Index: test/clang-modernize/UseAuto/Inputs/test_std_container.h<br>
> ===================================================================<br>
> --- test/clang-modernize/UseAuto/Inputs/test_std_container.h<br>
> +++ /dev/null<br>
> @@ -1,119 +0,0 @@<br>
> -//===-----------------------------------------------------------*- C++ -*--===//<br>
> -//<br>
> -// This file contains a shell implementation of a standard container with<br>
> -// iterators. This shell is targeted at supporting the container interfaces<br>
> -// recognized by clang-modernize's use-auto transformation. It requires the<br>
> -// preprocessor to parameterize the name of the container, and allows the<br>
> -// preprocessor to parameterize various mechanisms used in the implementation<br>
> -// of the container / iterator.<br>
> -//<br>
> -// Variations for how iterator types are presented:<br>
> -// * Typedef (array, deque, forward_list, list, vector)<br>
> -// * Nested class (map, multimap, set, multiset)<br>
> -// * Using declaration {unordered_} X {map, multimap, set, multiset}<br>
> -//<br>
> -// Variations for how container types are presented:<br>
> -// * Defined directly in namespace std<br>
> -// * Imported into namespace std with using declarations (a la libc++).<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef CONTAINER<br>
> -#error You must define CONTAINER to the name of the desired container.<br>
> -#endif<br>
> -<br>
> -// If the test code needs multiple containers, only define our helpers once.<br>
> -#ifndef TEST_STD_CONTAINER_HELPERS<br>
> -#define TEST_STD_CONTAINER_HELPERS<br>
> -<br>
> -namespace internal {<br>
> -<br>
> -template <typename T, int i><br>
> -struct iterator_wrapper {<br>
> - iterator_wrapper() {}<br>
> -<br>
> - // These are required for tests using iteration statements.<br>
> - bool operator!=(const iterator_wrapper<T, i>&) { return false; }<br>
> - iterator_wrapper& operator++() { return *this; }<br>
> - typename T::value_type operator*() { return typename T::value_type(); }<br>
> -};<br>
> -<br>
> -template <typename T><br>
> -class iterator_provider {<br>
> -public:<br>
> - class iterator {<br>
> - public:<br>
> - iterator() {}<br>
> - iterator(const iterator&) {}<br>
> - };<br>
> - class const_iterator {<br>
> - public:<br>
> - const_iterator(int i=0) {}<br>
> - const_iterator(const iterator &) {}<br>
> - const_iterator(const const_iterator &) {}<br>
> - operator iterator() { return iterator(); }<br>
> - };<br>
> - class reverse_iterator {};<br>
> - class const_reverse_iterator {};<br>
> -};<br>
> -<br>
> -} // namespace internal<br>
> -<br>
> -#endif // TEST_STD_CONTAINER_HELPERS<br>
> -<br>
> -namespace std {<br>
> -<br>
> -#if USE_INLINE_NAMESPACE<br>
> -inline namespace _1 {<br>
> -#endif<br>
> -<br>
> -template <typename T><br>
> -class CONTAINER<br>
> -#if USE_BASE_CLASS_ITERATORS<br>
> - : internal::iterator_provider<CONTAINER<T> ><br>
> -#endif<br>
> -{<br>
> -public:<br>
> -<br>
> -#if USE_BASE_CLASS_ITERATORS<br>
> - using typename internal::iterator_provider<CONTAINER<T> >::iterator;<br>
> - using typename internal::iterator_provider<CONTAINER<T> >::const_iterator;<br>
> - using typename internal::iterator_provider<CONTAINER<T> >::reverse_iterator;<br>
> - using typename internal::iterator_provider<CONTAINER<T> >::const_reverse_iterator;<br>
> -#elif USE_INNER_CLASS_ITERATORS<br>
> - class iterator {};<br>
> - class const_iterator {};<br>
> - class reverse_iterator {};<br>
> - class const_reverse_iterator {};<br>
> -#else<br>
> - typedef T value_type;<br>
> - typedef typename internal::iterator_wrapper<CONTAINER<T>, 0> iterator;<br>
> - typedef typename internal::iterator_wrapper<CONTAINER<T>, 1> const_iterator;<br>
> - typedef typename internal::iterator_wrapper<CONTAINER<T>, 3> reverse_iterator;<br>
> - typedef typename internal::iterator_wrapper<CONTAINER<T>, 2> const_reverse_iterator;<br>
> -#endif<br>
> -<br>
> - // Every class requires these functions.<br>
> - CONTAINER() {}<br>
> -<br>
> - iterator begin() { return iterator(); }<br>
> - iterator end() { return iterator(); }<br>
> -<br>
> - const_iterator begin() const { return const_iterator(); }<br>
> - const_iterator end() const { return const_iterator(); }<br>
> -<br>
> - reverse_iterator rbegin() { return reverse_iterator(); }<br>
> - reverse_iterator rend() { return reverse_iterator(); }<br>
> -<br>
> - const_reverse_iterator rbegin() const { return const_reverse_iterator(); }<br>
> - const_reverse_iterator rend() const { return const_reverse_iterator(); }<br>
> -<br>
> - template <typename K><br>
> - iterator find(const K &Key) { return iterator(); }<br>
> -};<br>
> -<br>
> -#if USE_INLINE_NAMESPACE<br>
> -} // namespace _1<br>
> -#endif<br>
> -<br>
> -} // namespace std<br>
> Index: test/clang-modernize/ReplaceAutoPtr/template_fail.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/ReplaceAutoPtr/template_fail.cpp<br>
> +++ /dev/null<br>
> @@ -1,31 +0,0 @@<br>
> -// XFAIL: *<br>
> -//<br>
> -// Without inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// With inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11 \<br>
> -// RUN: -DUSE_INLINE_NAMESPACE=1<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -#include "memory_stub.h"<br>
> -<br>
> -// Fail to modify when the template is never instantiated.<br>
> -//<br>
> -// This might not be an issue. If it's never used it doesn't really matter if<br>
> -// it's changed or not. If it's a header and one of the source use it, then it<br>
> -// will still be changed.<br>
> -template <typename X><br>
> -void f() {<br>
> - std::auto_ptr<X> p;<br>
> - // CHECK: std::unique_ptr<X> p;<br>
> -}<br>
> -<br>
> -// Alias template could be replaced if a matcher existed.<br>
> -template <typename T> using aaaaaaaa = auto_ptr<T>;<br>
> -// CHECK: template <typename T> using aaaaaaaa = unique_ptr<T>;<br>
> Index: test/clang-modernize/ReplaceAutoPtr/move.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/ReplaceAutoPtr/move.cpp<br>
> +++ /dev/null<br>
> @@ -1,63 +0,0 @@<br>
> -// Without inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -//<br>
> -// With inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: clang-modernize -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11 \<br>
> -// RUN: -DUSE_INLINE_NAMESPACE=1<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -<br>
> -#include "memory_stub.h"<br>
> -<br>
> -void takes_ownership_fn(std::auto_ptr<int> x);<br>
> -// CHECK: void takes_ownership_fn(std::unique_ptr<int> x);<br>
> -<br>
> -std::auto_ptr<int> get_by_value();<br>
> -// CHECK: std::unique_ptr<int> get_by_value();<br>
> -<br>
> -class Wrapper {<br>
> -public:<br>
> - std::auto_ptr<int> &get_wrapped();<br>
> -<br>
> -private:<br>
> - std::auto_ptr<int> wrapped;<br>
> -};<br>
> -<br>
> -void f() {<br>
> - std::auto_ptr<int> a, b, c;<br>
> - // CHECK: std::unique_ptr<int> a, b, c;<br>
> - Wrapper wrapper_a, wrapper_b;<br>
> -<br>
> - a = b;<br>
> - // CHECK: a = std::move(b);<br>
> -<br>
> - wrapper_a.get_wrapped() = wrapper_b.get_wrapped();<br>
> - // CHECK: wrapper_a.get_wrapped() = std::move(wrapper_b.get_wrapped());<br>
> -<br>
> - // Test that 'std::move()' is inserted when call to the<br>
> - // copy-constructor are made.<br>
> - takes_ownership_fn(c);<br>
> - // CHECK: takes_ownership_fn(std::move(c));<br>
> - takes_ownership_fn(wrapper_a.get_wrapped());<br>
> - // CHECK: takes_ownership_fn(std::move(wrapper_a.get_wrapped()));<br>
> -<br>
> - std::auto_ptr<int> d[] = { std::auto_ptr<int>(new int(1)),<br>
> - std::auto_ptr<int>(new int(2)) };<br>
> - std::auto_ptr<int> e = d[0];<br>
> - // CHECK: std::unique_ptr<int> d[] = { std::unique_ptr<int>(new int(1)),<br>
> - // CHECK-NEXT: std::unique_ptr<int>(new int(2)) };<br>
> - // CHECK-NEXT: std::unique_ptr<int> e = std::move(d[0]);<br>
> -<br>
> - // Test that std::move() is not used when assigning an rvalue<br>
> - std::auto_ptr<int> f;<br>
> - f = std::auto_ptr<int>(new int(0));<br>
> - // CHECK: std::unique_ptr<int> f;<br>
> - // CHECK-NEXT: f = std::unique_ptr<int>(new int(0));<br>
> -<br>
> - std::auto_ptr<int> g = get_by_value();<br>
> - // CHECK: std::unique_ptr<int> g = get_by_value();<br>
> -}<br>
> Index: test/clang-modernize/ReplaceAutoPtr/basic.cpp<br>
> ===================================================================<br>
> --- test/clang-modernize/ReplaceAutoPtr/basic.cpp<br>
> +++ /dev/null<br>
> @@ -1,154 +0,0 @@<br>
> -// RUN: mkdir -p %T/Inputs<br>
> -//<br>
> -// Without inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/memory_stub.h > %T/Inputs/memory_stub.h<br>
> -// RUN: clang-modernize -include=%T -replace-auto_ptr %t.cpp -- \<br>
> -// RUN: -std=c++11 -I %T<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h<br>
> -//<br>
> -// With inline namespace:<br>
> -//<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/basic.h > %T/Inputs/basic.h<br>
> -// RUN: grep -Ev "// *[A-Z-]+:" %S/Inputs/memory_stub.h > %T/Inputs/memory_stub.h<br>
> -// RUN: clang-modernize -include=%T -replace-auto_ptr %t.cpp -- \<br>
> -// RUN: -DUSE_INLINE_NAMESPACE=1 -std=c++11 -I %T<br>
> -// RUN: FileCheck -input-file=%t.cpp %s<br>
> -// RUN: FileCheck -input-file=%T/Inputs/basic.h %S/Inputs/basic.h<br>
> -<br>
> -#include "Inputs/basic.h"<br>
> -<br>
> -void f_1() {<br>
> - std::auto_ptr<int> a;<br>
> - // CHECK: std::unique_ptr<int> a;<br>
> -<br>
> - // check that spaces aren't modified unnecessarily<br>
> - std:: auto_ptr <int> b;<br>
> - // CHECK: std:: unique_ptr <int> b;<br>
> - std :: auto_ptr < char > c(new char());<br>
> - // CHECK: std :: unique_ptr < char > c(new char());<br>
> -<br>
> - // Test construction from a temporary<br>
> - std::auto_ptr<char> d = std::auto_ptr<char>();<br>
> - // CHECK: std::unique_ptr<char> d = std::unique_ptr<char>();<br>
> -<br>
> - typedef std::auto_ptr<int> int_ptr_t;<br>
> - // CHECK: typedef std::unique_ptr<int> int_ptr_t;<br>
> - int_ptr_t e(new int());<br>
> - // CHECK: int_ptr_t e(new int());<br>
> -<br>
> - // Test pointers<br>
> - std::auto_ptr<int> *f;<br>
> - // CHECK: std::unique_ptr<int> *f;<br>
> -<br>
> - // Test 'static' declarations<br>
> - static std::auto_ptr<int> g;<br>
> - // CHECK: static std::unique_ptr<int> g;<br>
> -<br>
> - // Test with cv-qualifiers<br>
> - const std::auto_ptr<int> h;<br>
> - // CHECK: const std::unique_ptr<int> h;<br>
> - volatile std::auto_ptr<int> i;<br>
> - // CHECK: volatile std::unique_ptr<int> i;<br>
> - const volatile std::auto_ptr<int> j;<br>
> - // CHECK: const volatile std::unique_ptr<int> j;<br>
> -<br>
> - // Test auto and initializer-list<br>
> - auto k = std::auto_ptr<int>{};<br>
> - // CHECK: auto k = std::unique_ptr<int>{};<br>
> - std::auto_ptr<int> l{std::auto_ptr<int>()};<br>
> - // CHECK: std::unique_ptr<int> l{std::unique_ptr<int>()};<br>
> -<br>
> - // Test interlocked auto_ptr<br>
> - std::auto_ptr<std::auto_ptr<int> > m;<br>
> - // CHECK: std::unique_ptr<std::unique_ptr<int> > m;<br>
> -<br>
> - // Test temporaries<br>
> - std::auto_ptr<char>();<br>
> - // CHECK: std::unique_ptr<char>();<br>
> -<br>
> - // Test void-specialization<br>
> - std::auto_ptr<void> n;<br>
> - // CHECK: std::unique_ptr<void> n;<br>
> -<br>
> - // Test template WITH instantiation (instantiation)<br>
> - B<double> o;<br>
> - std::auto_ptr<double> p(o.create());<br>
> - // CHECK: std::unique_ptr<double> p(o.create());<br>
> -<br>
> - // Test 'using' in a namespace ("definition")<br>
> - ns_1::auto_ptr<int> q;<br>
> - // CHECK: ns_1::unique_ptr<int> q;<br>
> -<br>
> - // Test construction with an 'auto_ptr_ref'<br>
> - std::auto_ptr<Base> r(create_derived_ptr());<br>
> - // CHECK: std::unique_ptr<Base> r(create_derived_ptr());<br>
> -}<br>
> -<br>
> -// Test without the nested name specifiers<br>
> -void f_2() {<br>
> - using namespace std;<br>
> -<br>
> - auto_ptr<int> a;<br>
> - // CHECK: unique_ptr<int> a;<br>
> -}<br>
> -<br>
> -// Test using declaration<br>
> -void f_3() {<br>
> - using std::auto_ptr;<br>
> - // CHECK: using std::unique_ptr;<br>
> -<br>
> - auto_ptr<int> a;<br>
> - // CHECK: unique_ptr<int> a;<br>
> -}<br>
> -<br>
> -// Test messing-up with macros<br>
> -void f_4() {<br>
> -#define MACRO_1 <char><br>
> - std::auto_ptr MACRO_1 p(new char());<br>
> -// CHECK: std::unique_ptr MACRO_1 p(new char());<br>
> -#define MACRO_2 auto_ptr<br>
> - std::MACRO_2<int> q;<br>
> -// CHECK: #define MACRO_2 unique_ptr<br>
> -#define MACRO_3(Type) std::auto_ptr<Type><br>
> - MACRO_3(float)r(new float());<br>
> -// CHECK: #define MACRO_3(Type) std::unique_ptr<Type><br>
> -#define MACRO_4 std::auto_ptr<br>
> - using MACRO_4;<br>
> -// CHECK: #define MACRO_4 std::unique_ptr<br>
> -#undef MACRO_1<br>
> -#undef MACRO_2<br>
> -#undef MACRO_3<br>
> -#undef MACRO_4<br>
> -}<br>
> -<br>
> -// Test function return values (definition)<br>
> -std::auto_ptr<char> f_5()<br>
> -// CHECK: std::unique_ptr<char> f_5()<br>
> -{<br>
> - // Test constructor<br>
> - return std::auto_ptr<char>(new char());<br>
> - // CHECK: return std::unique_ptr<char>(new char());<br>
> -}<br>
> -<br>
> -// Test that non-std auto_ptr aren't replaced<br>
> -void f_8() {<br>
> - ns_2::auto_ptr<char> a;<br>
> - // CHECK: ns_2::auto_ptr<char> a;<br>
> - using namespace ns_2;<br>
> - auto_ptr<int> b;<br>
> - // CHECK: auto_ptr<int> b;<br>
> -}<br>
> -<br>
> -namespace std {<br>
> -template <typename T> using aaaaaaaa = auto_ptr<T>;<br>
> -}<br>
> -// We want to avoid replacing 'aaaaaaaa' by unique_ptr here. It's better to<br>
> -// change the type alias directly.<br>
> -// XXX: maybe another test will be more relevant to test this potential error.<br>
> -std::aaaaaaaa<int> d;<br>
> -// CHECK: std::aaaaaaaa<int> d;<br>
> Index: test/clang-modernize/ReplaceAutoPtr/Inputs/memory_stub.h<br>
> ===================================================================<br>
> --- test/clang-modernize/ReplaceAutoPtr/Inputs/memory_stub.h<br>
> +++ /dev/null<br>
> @@ -1,61 +0,0 @@<br>
> -//===-----------------------------------------------------------*- C++ -*--===//<br>
> -//<br>
> -// This file contains a shell implementation of the 'auto_ptr' type from the<br>
> -// standard library. This shell aims to support the variations between standard<br>
> -// library implementations.<br>
> -//<br>
> -// Variations for how 'auto_ptr' is presented:<br>
> -// 1. Defined directly in namespace std<br>
> -// 2. Use a versioned inline namespace in std (default on libc++).<br>
> -//<br>
> -// Use the preprocessor to define USE_INLINE_NAMESPACE=1 and use the second<br>
> -// variation.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -namespace std {<br>
> -<br>
> -#if USE_INLINE_NAMESPACE<br>
> -inline namespace _1 {<br>
> -#endif<br>
> -<br>
> -template <class Y> struct auto_ptr_ref {<br>
> - Y *y_;<br>
> -};<br>
> -<br>
> -template <class X> class auto_ptr {<br>
> -public:<br>
> - typedef X element_type;<br>
> - // D.10.1.1 construct/copy/destroy:<br>
> - explicit auto_ptr(X *p = 0) throw() {}<br>
> - auto_ptr(auto_ptr &) throw() {}<br>
> - template <class Y> auto_ptr(auto_ptr<Y> &) throw() {}<br>
> - auto_ptr &operator=(auto_ptr &) throw() { return *this; }<br>
> - template <class Y> auto_ptr &operator=(auto_ptr<Y> &) throw() {<br>
> - return *this;<br>
> - }<br>
> - auto_ptr &operator=(auto_ptr_ref<X> r) throw() { return *this; }<br>
> - ~auto_ptr() throw() {}<br>
> - // D.10.1.3 conversions:<br>
> - auto_ptr(auto_ptr_ref<X> r) throw() : x_(r.y_) {}<br>
> - template <class Y> operator auto_ptr_ref<Y>() throw() {<br>
> - auto_ptr_ref<Y> r;<br>
> - r.y_ = x_;<br>
> - return r;<br>
> - }<br>
> - template <class Y> operator auto_ptr<Y>() throw() { return auto_ptr<Y>(x_); }<br>
> -<br>
> -private:<br>
> - X *x_;<br>
> -};<br>
> -<br>
> -template <> class auto_ptr<void> {<br>
> -public:<br>
> - typedef void element_type;<br>
> -};<br>
> -<br>
> -#if USE_INLINE_NAMESPACE<br>
> -} // namespace _1<br>
> -#endif<br>
> -<br>
> -} // end namespace std<br>
> Index: test/clang-modernize/ReplaceAutoPtr/Inputs/basic.h<br>
> ===================================================================<br>
> --- test/clang-modernize/ReplaceAutoPtr/Inputs/basi...</blockquote></div>