Index: include/clang/Tooling/CompilationDatabase.h =================================================================== --- include/clang/Tooling/CompilationDatabase.h +++ include/clang/Tooling/CompilationDatabase.h @@ -59,6 +59,15 @@ /// The output file associated with the command. std::string Output; + + friend bool operator==(const CompileCommand &LHS, const CompileCommand &RHS) { + return LHS.Directory == RHS.Directory && LHS.Filename == RHS.Filename && + LHS.CommandLine == RHS.CommandLine && LHS.Output == RHS.Output; + } + + friend bool operator!=(const CompileCommand &LHS, const CompileCommand &RHS) { + return !(LHS == RHS); + } }; /// Interface for compilation databases. Index: unittests/Tooling/CompilationDatabaseTest.cpp =================================================================== --- unittests/Tooling/CompilationDatabaseTest.cpp +++ unittests/Tooling/CompilationDatabaseTest.cpp @@ -736,5 +736,33 @@ EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D FOO/BAR/BAZ/SHOUT.cc"); } +TEST(CompileCommandTest, EqualityOperator) { + CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o"); + CompileCommand CCTest = CCRef; + + EXPECT_TRUE(CCRef == CCTest); + EXPECT_FALSE(CCRef != CCTest); + + CCTest = CCRef; + CCTest.Directory = "/foo/baz"; + EXPECT_FALSE(CCRef == CCTest); + EXPECT_TRUE(CCRef != CCTest); + + CCTest = CCRef; + CCTest.Filename = "bonjour.c"; + EXPECT_FALSE(CCRef == CCTest); + EXPECT_TRUE(CCRef != CCTest); + + CCTest = CCRef; + CCTest.CommandLine.push_back("c"); + EXPECT_FALSE(CCRef == CCTest); + EXPECT_TRUE(CCRef != CCTest); + + CCTest = CCRef; + CCTest.Output = "bonjour.o"; + EXPECT_FALSE(CCRef == CCTest); + EXPECT_TRUE(CCRef != CCTest); +} + } // end namespace tooling } // end namespace clang