Avoid deprecated std::filesystem::path::string
...and std::filesystem::path::generic_string, which at least GCC 17 trunk
libstdc++ now flags for C++26 (--with-latest-c++) as
> In file included from engine/codemaker/source/netmaker/netproduce.cxx:19:
> engine/codemaker/source/netmaker/csharpfile.hxx:28:53: error: 'string' is deprecated: use 'display_string' or 'native_encoded_string' instead [-Werror,-Wdeprecated-declarations]
> 28 | std::string getPath() const { return m_filePath.string(); }
> | ^
> ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/fs_path.h:465:5: note: 'string' has been explicitly marked deprecated here
> 465 | _GLIBCXX26_DEPRECATED_SUGGEST("display_string' or 'native_encoded_string")
> | ^
> ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-pc-linux-gnu/bits/c++config.h:160:45: note: expanded from macro '_GLIBCXX26_DEPRECATED_SUGGEST'
> 160 | # define _GLIBCXX26_DEPRECATED_SUGGEST(ALT) _GLIBCXX_DEPRECATED_SUGGEST(ALT)
> | ^
> ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-pc-linux-gnu/bits/c++config.h:112:19: note: expanded from macro '_GLIBCXX_DEPRECATED_SUGGEST'
> 112 | __attribute__ ((__deprecated__ ("use '" ALT "' instead")))
> | ^
since
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=341ad729c2c93b9f01854913b0404e4fc8958512>
"libstdc++: Add (generic_)display_string and (generic_)native_encoded_string to
filesystem::path".
Occurrences that are obviously meant for display purposes are #if-conditionally
replaced with the new display_string, while all other occurrences are left using
the (non-deprecated) [generic_]string<char> template instantiation, matching the
original code. (Where, for C++26, the latter could also be replaced with the
new [generic_]native_encoded_string, aka [generic_]system_encoded_string; see
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2319r5.html>
"Prevent path presentation problems" and
<https://cplusplus.github.io/LWG/issue4512> "The system_encoded_string() and
generic_system_encoded_string() member functions of std::filesystem::path are
misnamed" for details.)
Signed-off-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Change-Id: I7c79c8522608550bb1e0f4cb8e4824480952446b
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/3987
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit f320d95d89ecc9bea81182795969f83b05ec903c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206226
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
committed by
Xisco Fauli
parent
f5c0446b86
commit
0e2ad911d9
@@ -25,7 +25,14 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
std::string getPath() const { return m_filePath.string(); }
|
||||
std::string getPath() const
|
||||
{
|
||||
#if defined __cpp_lib_format_path
|
||||
return m_filePath.display_string();
|
||||
#else
|
||||
return m_filePath.string<char>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void openFile()
|
||||
{
|
||||
|
||||
@@ -151,7 +151,7 @@ OString CppIncludeManager::calculateRelativeIncludePath(const CppFile& file,
|
||||
// If they're in the same directory, just use the filename
|
||||
if (target.parent_path() == currentDir)
|
||||
{
|
||||
std::string result = target.filename().string();
|
||||
std::string result = target.filename().string<char>();
|
||||
return OString("\"" + result + "\"");
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ OString CppIncludeManager::calculateRelativeIncludePath(const CppFile& file,
|
||||
rel = fs::relative(target, baseDir);
|
||||
}
|
||||
|
||||
std::string result = rel.generic_string();
|
||||
std::string result = rel.generic_string<char>();
|
||||
return OString("\"" + result + "\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,14 @@ RustFile::RustFile(std::string_view directory, std::string_view typeName)
|
||||
{
|
||||
}
|
||||
|
||||
std::string RustFile::getPath() const { return m_filePath.string(); }
|
||||
std::string RustFile::getPath() const
|
||||
{
|
||||
#if defined __cpp_lib_format_path
|
||||
return m_filePath.display_string();
|
||||
#else
|
||||
return m_filePath.string<char>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RustFile::openFile()
|
||||
{
|
||||
@@ -255,7 +262,7 @@ void RustFile::addFileToModDeclaration()
|
||||
{
|
||||
std::filesystem::path parentDir = m_filePath.parent_path();
|
||||
std::filesystem::path modFile = parentDir / "mod.rs";
|
||||
std::string fileName = m_filePath.stem().string(); // Get filename without extension
|
||||
std::string fileName = m_filePath.stem().string<char>(); // Get filename without extension
|
||||
|
||||
if (std::filesystem::exists(modFile))
|
||||
{
|
||||
@@ -294,12 +301,12 @@ void RustFile::ensureModFileExists(const std::filesystem::path& dirPath)
|
||||
{
|
||||
if (entry.is_directory())
|
||||
{
|
||||
std::string dirName = entry.path().filename().string();
|
||||
std::string dirName = entry.path().filename().string<char>();
|
||||
childModules.push_back(dirName);
|
||||
}
|
||||
else if (entry.is_regular_file() && entry.path().extension() == ".rs")
|
||||
{
|
||||
std::string fileName = entry.path().stem().string();
|
||||
std::string fileName = entry.path().stem().string<char>();
|
||||
if (fileName != "mod") // Don't include mod.rs itself
|
||||
{
|
||||
childModules.push_back(fileName);
|
||||
@@ -327,7 +334,7 @@ void RustFile::ensureModFileExists(const std::filesystem::path& dirPath)
|
||||
|
||||
if (parentDir >= outputRoot)
|
||||
{
|
||||
std::string moduleName = dirPath.filename().string();
|
||||
std::string moduleName = dirPath.filename().string<char>();
|
||||
|
||||
if (parentDir.filename() == "src")
|
||||
{
|
||||
@@ -452,9 +459,16 @@ CppFile::CppFile(std::string_view directory, std::string_view typeName, std::str
|
||||
{
|
||||
}
|
||||
|
||||
std::string CppFile::getPathString() const { return m_filePath.string(); }
|
||||
std::string CppFile::getPathString() const
|
||||
{
|
||||
#if defined __cpp_lib_format_path
|
||||
return m_filePath.display_string();
|
||||
#else
|
||||
return m_filePath.string<char>();
|
||||
#endif
|
||||
}
|
||||
std::filesystem::path CppFile::getPath() const { return m_filePath; }
|
||||
std::string CppFile::getExtension() const { return m_filePath.extension().string(); }
|
||||
std::string CppFile::getExtension() const { return m_filePath.extension().string<char>(); }
|
||||
|
||||
void CppFile::openFile()
|
||||
{
|
||||
@@ -619,14 +633,14 @@ void RustFile::processDirectoryRecursively(const std::filesystem::path& currentD
|
||||
{
|
||||
if (entry.is_directory())
|
||||
{
|
||||
std::string dirName = entry.path().filename().string();
|
||||
std::string dirName = entry.path().filename().string<char>();
|
||||
childModules.push_back(dirName);
|
||||
// Recursively process subdirectory
|
||||
processDirectoryRecursively(entry.path());
|
||||
}
|
||||
else if (entry.is_regular_file() && entry.path().extension() == ".rs")
|
||||
{
|
||||
std::string fileName = entry.path().stem().string();
|
||||
std::string fileName = entry.path().stem().string<char>();
|
||||
if (fileName != "mod" && fileName != "lib") // Don't include mod.rs or lib.rs
|
||||
{
|
||||
childModules.push_back(fileName);
|
||||
|
||||
@@ -159,7 +159,7 @@ std::string GtvHelpers::getRelativePath(const std::string& aFilePath)
|
||||
if (err)
|
||||
return aFilePath;
|
||||
|
||||
return aRelPath.string();
|
||||
return aRelPath.string<char>();
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
Reference in New Issue
Block a user