From: Daniel Dunbar Date: Sun, 6 Dec 2009 09:56:30 +0000 (+0000) Subject: Document that CompilerInvocation::createDiagnostics keeps a reference to the Diagnost... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb3503a146f5eee6393a8b7542f38d9f5fce6583;p=clang Document that CompilerInvocation::createDiagnostics keeps a reference to the DiagnosticOptions, and update callers to make sure they don't pass in a temporary. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90704 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp index cca7907ba0..ae789fa9ae 100644 --- a/examples/wpa/clang-wpa.cpp +++ b/examples/wpa/clang-wpa.cpp @@ -33,8 +33,9 @@ int main(int argc, char **argv) { if (InputFilenames.empty()) return 0; + DiagnosticOptions DiagOpts; llvm::OwningPtr Diags( - CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv)); + CompilerInstance::createDiagnostics(DiagOpts, argc, argv)); for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 27153b63c8..18ec429db7 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -419,9 +419,13 @@ public: /// logging information. /// /// Note that this creates an unowned DiagnosticClient, if using directly the - /// caller is responsible for releaseing the returned Diagnostic's client + /// caller is responsible for releasing the returned Diagnostic's client /// eventually. /// + /// \param Opts - The diagnostic options; note that the created text + /// diagnostic object contains a reference to these options and its lifetime + /// must extend past that of the diagnostic engine. + /// /// \return The new object on success, or null on failure. static Diagnostic *createDiagnostics(const DiagnosticOptions &Opts, int Argc, char **Argv); diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 9259818e0e..5e8e02df1a 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -292,6 +292,7 @@ public: }; class CIndexer : public Indexer { + DiagnosticOptions DiagOpts; IgnoreDiagnosticsClient IgnoreDiagClient; llvm::OwningPtr TextDiags; Diagnostic IgnoreDiags; @@ -308,7 +309,7 @@ public: OnlyLocalDecls(false), DisplayDiagnostics(false) { TextDiags.reset( - CompilerInstance::createDiagnostics(DiagnosticOptions(), 0, 0)); + CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); } virtual ~CIndexer() { delete &getProgram(); } diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index d13b2d4926..0b1971f797 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -238,8 +238,9 @@ int main(int argc, char **argv) { Indexer Idxer(Prog); llvm::SmallVector TUnits; + DiagnosticOptions DiagOpts; llvm::OwningPtr Diags( - CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv)); + CompilerInstance::createDiagnostics(DiagOpts, argc, argv)); // If no input was specified, read from stdin. if (InputFilenames.empty())