[clang] eccc648 - [Clang] Remove __is_nullptr (#99038)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 4 01:34:08 PDT 2024
Author: Nikolas Klauser
Date: 2024-08-04T10:34:04+02:00
New Revision: eccc6487c1fc5925ea2e595b5b07a31976c3232e
URL: https://github.com/llvm/llvm-project/commit/eccc6487c1fc5925ea2e595b5b07a31976c3232e
DIFF: https://github.com/llvm/llvm-project/commit/eccc6487c1fc5925ea2e595b5b07a31976c3232e.diff
LOG: [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.
Added:
Modified:
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp
Removed:
################################################################################
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index a747464582e77..9dcb4ac9b75ca 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1615,10 +1615,6 @@ The following type trait primitives are supported by Clang. Those traits marked
* ``__is_nothrow_assignable`` (C++, MSVC 2013)
* ``__is_nothrow_constructible`` (C++, MSVC 2013)
* ``__is_nothrow_destructible`` (C++, MSVC 2013)
-* ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
- Returns true for ``std::nullptr_t`` and false for everything else. The
- corresponding standard library feature is ``std::is_null_pointer``, but
- ``__is_null_pointer`` is already in use by some implementations.
* ``__is_object`` (C++, Embarcadero)
* ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
Note, the corresponding standard trait was deprecated in C++20.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3d76bd3ae272f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,10 @@ C/C++ Language Potentially Breaking Changes
C++ Specific Potentially Breaking Changes
-----------------------------------------
+- The type trait builtin ``__is_nullptr`` has been removed, since it has very
+ few users and can be written as ``__is_same(__remove_cv(T), decltype(nullptr))``,
+ which GCC supports as well.
+
ABI Changes in This Version
---------------------------
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..aac89d910bbc8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,7 +447,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
///
/// HLSL: Parse export function declaration.
///
-/// export-function-declaration:
+/// export-function-declaration:
/// 'export' function-declaration
///
/// export-declaration-group:
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
tok::kw___is_nothrow_constructible,
tok::kw___is_nothrow_convertible,
tok::kw___is_nothrow_destructible,
- tok::kw___is_nullptr,
tok::kw___is_object,
tok::kw___is_pod,
tok::kw___is_pointer,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e501d5e91e77d..826e7b603ee82 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -802,7 +802,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
- REVERTIBLE_TYPE_TRAIT(__is_nullptr);
REVERTIBLE_TYPE_TRAIT(__is_object);
REVERTIBLE_TYPE_TRAIT(__is_pod);
REVERTIBLE_TYPE_TRAIT(__is_pointer);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..124435330ca10 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4982,7 +4982,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
case UTT_IsArray:
case UTT_IsBoundedArray:
case UTT_IsPointer:
- case UTT_IsNullPointer:
case UTT_IsReferenceable:
case UTT_IsLvalueReference:
case UTT_IsRvalueReference:
@@ -5241,8 +5240,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
return T->isIncompleteArrayType();
case UTT_IsPointer:
return T->isAnyPointerType();
- case UTT_IsNullPointer:
- return T->isNullPtrType();
case UTT_IsLvalueReference:
return T->isLValueReferenceType();
case UTT_IsRvalueReference:
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index 4acb3d6c9eebe..e5d2ced3caaed 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1041,42 +1041,6 @@ void is_pointer()
static_assert(!__is_pointer(void (StructWithMembers::*) ()));
}
-void is_null_pointer() {
- StructWithMembers x;
-
- static_assert(__is_nullptr(decltype(nullptr)));
- static_assert(!__is_nullptr(void *));
- static_assert(!__is_nullptr(cvoid *));
- static_assert(!__is_nullptr(cvoid *));
- static_assert(!__is_nullptr(char *));
- static_assert(!__is_nullptr(int *));
- static_assert(!__is_nullptr(int **));
- static_assert(!__is_nullptr(ClassType *));
- static_assert(!__is_nullptr(Derives *));
- static_assert(!__is_nullptr(Enum *));
- static_assert(!__is_nullptr(IntArNB *));
- static_assert(!__is_nullptr(Union *));
- static_assert(!__is_nullptr(UnionAr *));
- static_assert(!__is_nullptr(StructWithMembers *));
- static_assert(!__is_nullptr(void (*)()));
-
- static_assert(!__is_nullptr(void));
- static_assert(!__is_nullptr(cvoid));
- static_assert(!__is_nullptr(cvoid));
- static_assert(!__is_nullptr(char));
- static_assert(!__is_nullptr(int));
- static_assert(!__is_nullptr(int));
- static_assert(!__is_nullptr(ClassType));
- static_assert(!__is_nullptr(Derives));
- static_assert(!__is_nullptr(Enum));
- static_assert(!__is_nullptr(IntArNB));
- static_assert(!__is_nullptr(Union));
- static_assert(!__is_nullptr(UnionAr));
- static_assert(!__is_nullptr(StructWithMembers));
- static_assert(!__is_nullptr(int StructWithMembers::*));
- static_assert(!__is_nullptr(void(StructWithMembers::*)()));
-}
-
void is_member_object_pointer()
{
StructWithMembers x;
More information about the cfe-commits
mailing list