diff --git a/include/boost/wave/util/cpp_include_paths.hpp b/include/boost/wave/util/cpp_include_paths.hpp index a438449d..e40d738f 100644 --- a/include/boost/wave/util/cpp_include_paths.hpp +++ b/include/boost/wave/util/cpp_include_paths.hpp @@ -178,6 +178,24 @@ class include_paths boost::filesystem::path current_dir; boost::filesystem::path current_rel_dir; + bool may_be_includable(const boost::filesystem::path& p) const + { + namespace fs = boost::filesystem; + if (!fs::exists(p) || fs::is_directory(p)) { + return false; + } + if (fs::is_symlink(p)) { + boost::system::error_code ec; + fs::file_status target = fs::status(p, ec); + if (ec || !fs::exists(target) || fs::is_directory(target)) { + return false; + } + return true; + } else { + return true; + } + } + #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0 public: bool has_pragma_once(std::string const &filename) @@ -328,7 +346,7 @@ bool include_paths::find_include_file (std::string &s, std::string &dir, currpath /= create_path(s); // append filename } - if (fs::exists(currpath)) { + if (may_be_includable(currpath)) { fs::path dirpath (create_path(s)); if (!dirpath.has_root_directory()) { dirpath = create_path((*it).second); @@ -362,7 +380,7 @@ include_paths::find_include_file (std::string &s, std::string &dir, currpath /= create_path(s); } - if (fs::exists(currpath) && 0 == current_file) { + if (0 == current_file && may_be_includable(currpath)) { // if 0 != current_path (#include_next handling) it can't be // the file in the current directory fs::path dirpath(create_path(s)); diff --git a/test/testwave/testfiles/t_2_032.cpp b/test/testwave/testfiles/t_2_032.cpp new file mode 100644 index 00000000..d890afb5 --- /dev/null +++ b/test/testwave/testfiles/t_2_032.cpp @@ -0,0 +1,17 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + http://www.boost.org/ + + Copyright (c) 2026 Rac75116. Distributed under the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +// Verify include lookup ignores directories named like the header. + +//O -I$P(t_2_032_dir) +//O -I$P(t_2_032_inc) + +//R #line 10 "t_2_032_target.hpp" +//R t_2_032_target_from_file +#include "t_2_032_target.hpp" diff --git a/test/testwave/testfiles/t_2_032_dir/t_2_032_target.hpp/dummy b/test/testwave/testfiles/t_2_032_dir/t_2_032_target.hpp/dummy new file mode 100644 index 00000000..e69de29b diff --git a/test/testwave/testfiles/t_2_032_inc/t_2_032_target.hpp b/test/testwave/testfiles/t_2_032_inc/t_2_032_target.hpp new file mode 100644 index 00000000..9261e986 --- /dev/null +++ b/test/testwave/testfiles/t_2_032_inc/t_2_032_target.hpp @@ -0,0 +1,10 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + http://www.boost.org/ + + Copyright (c) 2026 Rac75116. Distributed under the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +t_2_032_target_from_file diff --git a/test/testwave/testfiles/test.cfg b/test/testwave/testfiles/test.cfg index 23b4e2c0..4598b18e 100644 --- a/test/testwave/testfiles/test.cfg +++ b/test/testwave/testfiles/test.cfg @@ -84,6 +84,7 @@ t_2_028.cpp t_2_029.cpp t_2_030.cpp t_2_031.cpp +t_2_032.cpp # # t_3: Predefined macros