[gcc r17-3256] libstdc++: Ignore filesystem::canonical errors for /etc/localtime [PR125467]

Tomasz Kaminski via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <20260813093501.3A0824BA23D1__41416.1906157219$1786613711$gmane$org@sourceware.org>
https://gcc.gnu.org/g:4af34d33c9e006eb8a142fe09910e8d25c188a48

commit r17-3256-g4af34d33c9e006eb8a142fe09910e8d25c188a48
Author: Tomasz Kamiński <[email protected]>
Date:   Thu Aug 13 07:54:44 2026 +0200

    libstdc++: Ignore filesystem::canonical errors for /etc/localtime [PR125467]
    
    While the errors from realpath (and readlink before r17-2048-gcc195f7b11a406)
    are ignored (str is left empty), the filesystem::canonical path thrown
    exception in such situation. This patch ignores the error consistently,
    by using error_code overload of filesystem::canonical.
    
    The !ec check before str assignment is not necessary, as standard requires
    that filesystem::canonical returns empty path, but I think it helps
    readability.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/125467
            * src/c++20/tzdb.cc (tzdb::current_zone): Use error_code overload
            of filesystem::canonical to ignore errors.
    
    Reviewed-by: Jonathan Wakely <[email protected]>
    Signed-off-by: Tomasz Kamiński <[email protected]>

Diff:
---
 libstdc++-v3/src/c++20/tzdb.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index e358b778e2d6..0d004a8a6fea 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -2335,8 +2335,10 @@ constinit tzdb_list::_Node::NumLeapSeconds tzdb_list::_Node::num_leap_seconds;
 	str = p;
       }
 #else
-    string sbuf = std::filesystem::canonical("/etc/localtime").string();
-    str = sbuf;
+    error_code ec;
+    string sbuf = std::filesystem::canonical("/etc/localtime", ec).string();
+    if (!ec)
+      str = sbuf;
 #endif
 
     if (!str.empty() && str != "/etc/localtime")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.