[clang] Extend -Wnonportable-include-path with a warning about trailing whitespace or dots (PR #96960)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 06:10:41 PDT 2024


================
@@ -2098,6 +2098,23 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
     const FileEntry *LookupFromFile, StringRef &LookupFilename,
     SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
     ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
+
+  // Check for trailing whitespace or dots in the include path.
+  // This must be done before looking up the file, as Windows will still
+  // find the file even if there are trailing dots or whitespace.
+  size_t TrailingPos = Filename.find_last_not_of(" .");
+  if (TrailingPos != StringRef::npos && TrailingPos < Filename.size() - 1) {
+    StringRef TrimmedFilename = Filename.rtrim(" .");
+
+    auto Hint = isAngled
----------------
zmodem wrote:

Since you're providing fixits, it would be nice to have tests for them. Look at clang/test/Parser/extra-semi.cpp for an example.

https://github.com/llvm/llvm-project/pull/96960


More information about the cfe-commits mailing list