Page MenuHomePhabricator

[libc++] Use the using_if_exists attribute when provided
Needs ReviewPublic

Authored by ldionne on Oct 27 2020, 11:23 AM.

Details

Reviewers
rsmith
erik.pilkington
Group Reviewers
Restricted Project
Summary

As discussed on cfe-dev [1], use the using_if_exists Clang attribute when
the compiler supports it. This makes it easier to port libc++ on top of
new platforms that don't fully support the C Standard library.

Previously, libc++ would fail to build when trying to import a missing
declaration in a <cXXXX> header. With the attribute, the declaration will
simply not be imported into namespace std, and hence it won't be available
for libc++ to use. In many cases, the declarations were *not* actually
required for libc++ to work, so not importing them into namespace std is
acceptable.

The same thing could be achieved by conscious usage of #ifdef along
with platform detection, however that quickly creates a maintenance
problem as libc++ is ported to new platforms.

[1]: http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html

Diff Detail

Event Timeline

ldionne created this revision.Oct 27 2020, 11:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2020, 11:23 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne requested review of this revision.Oct 27 2020, 11:23 AM

Note that once this is in, we can also start dropping existing #ifs in the headers to workaround various declarations missing in the underlying C stdlib, as long as we require a sufficiently recent Clang.

Note that once this is in, we can also start dropping existing #ifs in the headers to workaround various declarations missing in the underlying C stdlib, as long as we require a sufficiently recent Clang.

What about other compilers?

Note that once this is in, we can also start dropping existing #ifs in the headers to workaround various declarations missing in the underlying C stdlib, as long as we require a sufficiently recent Clang.

What about other compilers?

We're not there yet -- I was just pointing to a possible future cleanup.

For other compilers: it seems reasonable to mandate that the attribute is supported on the compiler you're using if you're trying to port libc++ to a platform that doesn't provide a full standard library. It's a balance between ease-of-porting and ease-of-maintaining.