PiotrZSL added a comment.

In D152589#4418649 <https://reviews.llvm.org/D152589#4418649>, @ErezAmihud 
wrote:

> I want to make sure I understand.
> The ideal situation would be to create `misc-no-relative-includes` check that 
> checks for `..` in paths (meaning - relative paths), and have a `StrictMode` 
> which does the check for angled-bracket includes?
>
> BTW The reason I initially checked for angled-bracket includes is that 
> according to this <https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html> quote 
> includes search in paths relative to the current file, and the angled-bracket 
> includes check only in the defined include directories.
> In this case there is no risk that the include would get a file that is not 
> relative to the include directory the user specified in the compile flags.

But according to paper you can also do `-I<path to .cpp directory>`  and in 
.cpp you can do `#include <header.hpp>` and if that header.hpp exist near .cpp 
then this is still relative include.
For me we should do something like this:

  path_to_cpp_directory = absolutepath(dirname(main-file))
  include_file = argument to #include <> or #include ""
  if (exists(path_to_cpp_directory  + include_file))
    if (StrictMode || !absolutepath(path_to_cpp_directory  + 
include_file).starts_with(path_to_cpp_directory))
         // relative include, generate warning




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152589/new/

https://reviews.llvm.org/D152589

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to