GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

Libstdc++ ignores filesystem::canonical errors for /etc/localtime.

GCC's libstdc++ now gracefully handles errors from filesystem::canonical for /etc/localtime.

The libstdc++ library now uses an error_code overload of filesystem::canonical to ignore errors when resolving the /etc/localtime path. Previously, this could lead to exceptions being thrown, while other error-handling mechanisms for similar paths returned an empty string. This change ensures consistent error handling across different path resolution methods, preventing unexpected program termination.

In Details

This commit addresses an inconsistency in error handling within libstdc++'s timezone database functionality. Specifically, tzdb::current_zone previously threw an exception when filesystem::canonical encountered an error with /etc/localtime, whereas realpath and readlink would return an empty string. By switching to filesystem::canonical's error_code overload, the behavior is now consistent: errors result in an empty path being returned instead of an exception, aligning with the expected behavior for other path resolution functions.

For Context
filesystem::canonical
A C++ standard library function that resolves a given path to its canonical form, resolving symlinks and removing redundant components (like '.' or '..'). It can throw exceptions on error.
error_code overload
A version of a function that accepts an error_code object as an argument. Instead of throwing an exception on error, it reports the error through the provided error_code object, allowing for more controlled error handling.
tzdb
Time Zone Database, a collection of historical time zone information used by operating systems and libraries to correctly interpret local times.
/etc/localtime
A system file on Unix-like systems that specifies the local time zone and daylight saving rules for the system.
Filed Under: filesystemerror handling