Skip to content

Commit eccc648

Browse files
authored
[Clang] Remove __is_nullptr (#99038)
`is_null_pointer` can be implemented very efficiently as `__is_same(__remove_cv(T), decltype(nullptr))`. Since GCC supports both of these builtins as well, libc++ has no interest in using `__is_nullptr` instead. Furthermore, I could find only a single use in the wild (https://sourcegraph.com/search?q=context:global+__is_nullptr%28+-file:clang&patternType=keyword&sm=0). Because of these reasons I don't think it's worth keeping this builtin around.
1 parent 0dd8c0d commit eccc648

File tree

6 files changed

+5
-46
lines changed

6 files changed

+5
-46
lines changed

clang/docs/LanguageExtensions.rst

-4
Original file line numberDiff line numberDiff line change
@@ -1615,10 +1615,6 @@ The following type trait primitives are supported by Clang. Those traits marked
16151615
* ``__is_nothrow_assignable`` (C++, MSVC 2013)
16161616
* ``__is_nothrow_constructible`` (C++, MSVC 2013)
16171617
* ``__is_nothrow_destructible`` (C++, MSVC 2013)
1618-
* ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
1619-
Returns true for ``std::nullptr_t`` and false for everything else. The
1620-
corresponding standard library feature is ``std::is_null_pointer``, but
1621-
``__is_null_pointer`` is already in use by some implementations.
16221618
* ``__is_object`` (C++, Embarcadero)
16231619
* ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
16241620
Note, the corresponding standard trait was deprecated in C++20.

clang/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ C/C++ Language Potentially Breaking Changes
4343
C++ Specific Potentially Breaking Changes
4444
-----------------------------------------
4545

46+
- The type trait builtin ``__is_nullptr`` has been removed, since it has very
47+
few users and can be written as ``__is_same(__remove_cv(T), decltype(nullptr))``,
48+
which GCC supports as well.
49+
4650
ABI Changes in This Version
4751
---------------------------
4852

clang/lib/Parse/ParseDeclCXX.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
447447
///
448448
/// HLSL: Parse export function declaration.
449449
///
450-
/// export-function-declaration:
450+
/// export-function-declaration:
451451
/// 'export' function-declaration
452452
///
453453
/// export-declaration-group:
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
17991799
tok::kw___is_nothrow_constructible,
18001800
tok::kw___is_nothrow_convertible,
18011801
tok::kw___is_nothrow_destructible,
1802-
tok::kw___is_nullptr,
18031802
tok::kw___is_object,
18041803
tok::kw___is_pod,
18051804
tok::kw___is_pointer,

clang/lib/Parse/ParseExpr.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
802802
REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
803803
REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
804804
REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
805-
REVERTIBLE_TYPE_TRAIT(__is_nullptr);
806805
REVERTIBLE_TYPE_TRAIT(__is_object);
807806
REVERTIBLE_TYPE_TRAIT(__is_pod);
808807
REVERTIBLE_TYPE_TRAIT(__is_pointer);

clang/lib/Sema/SemaExprCXX.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -4982,7 +4982,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
49824982
case UTT_IsArray:
49834983
case UTT_IsBoundedArray:
49844984
case UTT_IsPointer:
4985-
case UTT_IsNullPointer:
49864985
case UTT_IsReferenceable:
49874986
case UTT_IsLvalueReference:
49884987
case UTT_IsRvalueReference:
@@ -5241,8 +5240,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
52415240
return T->isIncompleteArrayType();
52425241
case UTT_IsPointer:
52435242
return T->isAnyPointerType();
5244-
case UTT_IsNullPointer:
5245-
return T->isNullPtrType();
52465243
case UTT_IsLvalueReference:
52475244
return T->isLValueReferenceType();
52485245
case UTT_IsRvalueReference:

clang/test/SemaCXX/type-traits.cpp

-36
Original file line numberDiff line numberDiff line change
@@ -1041,42 +1041,6 @@ void is_pointer()
10411041
static_assert(!__is_pointer(void (StructWithMembers::*) ()));
10421042
}
10431043

1044-
void is_null_pointer() {
1045-
StructWithMembers x;
1046-
1047-
static_assert(__is_nullptr(decltype(nullptr)));
1048-
static_assert(!__is_nullptr(void *));
1049-
static_assert(!__is_nullptr(cvoid *));
1050-
static_assert(!__is_nullptr(cvoid *));
1051-
static_assert(!__is_nullptr(char *));
1052-
static_assert(!__is_nullptr(int *));
1053-
static_assert(!__is_nullptr(int **));
1054-
static_assert(!__is_nullptr(ClassType *));
1055-
static_assert(!__is_nullptr(Derives *));
1056-
static_assert(!__is_nullptr(Enum *));
1057-
static_assert(!__is_nullptr(IntArNB *));
1058-
static_assert(!__is_nullptr(Union *));
1059-
static_assert(!__is_nullptr(UnionAr *));
1060-
static_assert(!__is_nullptr(StructWithMembers *));
1061-
static_assert(!__is_nullptr(void (*)()));
1062-
1063-
static_assert(!__is_nullptr(void));
1064-
static_assert(!__is_nullptr(cvoid));
1065-
static_assert(!__is_nullptr(cvoid));
1066-
static_assert(!__is_nullptr(char));
1067-
static_assert(!__is_nullptr(int));
1068-
static_assert(!__is_nullptr(int));
1069-
static_assert(!__is_nullptr(ClassType));
1070-
static_assert(!__is_nullptr(Derives));
1071-
static_assert(!__is_nullptr(Enum));
1072-
static_assert(!__is_nullptr(IntArNB));
1073-
static_assert(!__is_nullptr(Union));
1074-
static_assert(!__is_nullptr(UnionAr));
1075-
static_assert(!__is_nullptr(StructWithMembers));
1076-
static_assert(!__is_nullptr(int StructWithMembers::*));
1077-
static_assert(!__is_nullptr(void(StructWithMembers::*)()));
1078-
}
1079-
10801044
void is_member_object_pointer()
10811045
{
10821046
StructWithMembers x;

0 commit comments

Comments
 (0)