diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2012-07-17 23:19:16 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2012-07-17 23:19:16 +0000 |
commit | a52f5a3ee2156849b3b91255c360b9f0bb1ebd51 (patch) | |
tree | e62038e0a147e93cd384274df5126d93b9bfbd5e /lib | |
parent | 8c77758b6546a61b7cc9b71d05049aa0fad3d841 (diff) |
Adding a fixit for includes that cannot be found with angle brackets, but can be found with quoted strings instead. Implements PR13201.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160406 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index a6b7b52624..74b9cbc881 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1390,9 +1390,28 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } if (File == 0) { - if (!SuppressIncludeNotFoundError) - Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; - return; + if (!SuppressIncludeNotFoundError) { + // If the file could not be located and it was included via angle + // brackets, we can attempt a lookup as though it were a quoted path to + // provide the user with a possible fixit. + if (isAngled) { + File = LookupFile(Filename, false, LookupFrom, CurDir, + Callbacks ? &SearchPath : 0, + Callbacks ? &RelativePath : 0, + getLangOpts().Modules ? &SuggestedModule : 0); + if (File) { + SourceRange Range(FilenameTok.getLocation(), CharEnd); + Diag(FilenameTok, diag::err_pp_file_not_found_not_fatal) << + Filename << + FixItHint::CreateReplacement(Range, "\"" + Filename.str() + "\""); + } + } + // If the file is still not found, just go with the vanilla diagnostic + if (!File) + Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; + } + if (!File) + return; } // If we are supposed to import a module rather than including the header, |