Re: [PATCH] libstdc++: Ignore filesystem::canonical errors for /etc/localtime [PR125467]

Tomasz Kaminski <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.libstdc++.devel
Message-ID <CAKvuMXBYr2ob9BVMBK5NAqrKWz18bcxDGR3wdHVQc8j02wFVgg@mail.gmail.com>
On Thu, Aug 13, 2026 at 8:46 AM Jonathan Wakely <[email protected]>
wrote:

>
>
> On Thu, 13 Aug 2026, 07:10 Tomasz Kamiński, <[email protected]> wrote:
>
>> 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.
>> ---
>> I agree there is inconsistency in treatment of filesystem errors, and
>> they seem to be consistently ignored on other paths. Torbjorn could you
>> confirm that this addresses the issue.
>> We will still need to wait for Jonathan to OK this.
>>
>> Not sure how to test this branch. But tested this change locally.
>> OK for trunk?
>>
>
> OK
>
I pushed it now.

>
> The newlib bug should still be fixed.
>
Yes, agreed.
My motivation was to properly support the cases where /etc/localtime is
missing,
and we fall back to "/etc/timezone",
 "/var/db/zoneinfo",  "/etc/sysconfig/clock" or
just "Etc/UTC". Currently, filesystem::canonical would just throw an
exception in this case.

>
>
>
>>  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 e358b778e2d..0d004a8a6fe 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")
>> --
>> 2.55.0
>>
>>
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.