
The approach in D30000 assumes that the '/' returned by path::begin() is the first element for absolute paths, but that's not true on Windows. Also, on Windows backslashes in include lines often end up escaped so that there are two of them. Having backslashes in include lines is undefined behavior in most cases and implementation-defined behavior in C++20, but since clang treats it as normal repeated path separators, the diagnostic should too. Unbreaks -Wnonportable-include-path for absolute paths on Windows, and unbreaks it on non-Windows in the case of absolute paths with repeated directory separators. This affects e.g. the `#include __FILE__` technique if the file passed to clang has the wrong case for the drive letter. Before: C:\src\llvm-project>bin\clang-cl.exe c:\src\llvm-project\test.cc c:\\src\\llvm-project\\test.cc(4,10): warning: non-portable path to file '"c\\srccllvm-projectctest.cc.'; specified path differs in case from file name on disk [-Wnonportable-include-path] ^ Now: C:\src\llvm-project> out\gn\bin\clang-cl c:\src\llvm-project\test.cc c:\\src\\llvm-project\\test.cc(4,10): warning: non-portable path to file '"C:\\src\\llvm-project\\test.cc"'; specified path differs in case from file name on disk [-Wnonportable-include-path] ^ Differential Revision: https://reviews.llvm.org/D79223
36 lines
2.2 KiB
C
36 lines
2.2 KiB
C
// REQUIRES: case-insensitive-filesystem
|
|
|
|
// RUN: mkdir -p %t/Output/apath
|
|
// RUN: mkdir -p %t/Output/asystempath
|
|
// RUN: cp %S/Inputs/case-insensitive-include.h %t/Output
|
|
// RUN: cp %S/Inputs/case-insensitive-include.h %t/Output/asystempath/case-insensitive-include2.h
|
|
// RUN: cd %t/Output
|
|
// RUN: %clang_cc1 -fsyntax-only %s -include %s -I %t/Output -isystem %t/Output/asystempath -verify
|
|
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -include %s -I %t/Output -isystem %t/Output/asystempath 2>&1 | FileCheck %s
|
|
|
|
// Known standard header, so warn:
|
|
#include <StdDef.h> // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:20}:"<stddef.h>"
|
|
|
|
#include "case-insensitive-include.h"
|
|
#include "Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:38}:"\"case-insensitive-include.h\""
|
|
|
|
#include "../Output/.//case-insensitive-include.h"
|
|
#include "../Output/.//Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:51}:"\"../Output/.//case-insensitive-include.h\""
|
|
#include "../output/.//case-insensitive-include.h" // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:51}:"\"../Output/.//case-insensitive-include.h\""
|
|
|
|
#include "apath/.././case-insensitive-include.h"
|
|
#include "apath/.././Case-Insensitive-Include.h" // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:49}:"\"apath/.././case-insensitive-include.h\""
|
|
#include "APath/.././case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(
|
|
|
|
#include "../Output/./apath/.././case-insensitive-include.h"
|
|
#include "../Output/./APath/.././case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(
|
|
#include "../output/./apath/.././case-insensitive-include.h" // expected-warning {{non-portable path}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:61}:"\"../Output/./apath/.././case-insensitive-include.h\""
|
|
|
|
#include "CASE-INSENSITIVE-INCLUDE2.H" // Found in an -isystem directory. No warning.
|