Skip to content

Commit 98395fd

Browse files
committed
[Clang] Fix __{add,remove}_pointer in Objective-C++
1 parent c25bd6e commit 98395fd

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ C++23 Feature Support
310310

311311
- Extend lifetime of temporaries in mem-default-init for P2718R0. Clang now fully
312312
supports `P2718R0 Lifetime extension in range-based for loops <https://wg21.link/P2718R0>`_.
313-
313+
314314
- ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
315315

316316
C++20 Feature Support
@@ -715,7 +715,7 @@ Improvements to Clang's diagnostics
715715

716716
- Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
717717

718-
- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
718+
- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings when an unrelated class
719719
defined a defaulted comparison operator (#GH116270).
720720

721721
.. code-block:: c++
@@ -832,6 +832,8 @@ Bug Fixes to Compiler Builtins
832832

833833
- Fix ``__builtin_source_location`` incorrectly returning wrong column for method chains. (#GH119129)
834834

835+
- The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for Objective-C++'s ``id`` and interfaces has been fixed.
836+
835837
Bug Fixes to Attribute Support
836838
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
837839

@@ -934,7 +936,7 @@ Bug Fixes to C++ Support
934936
- Fixed an assertion failure caused by invalid default argument substitutions in non-defining
935937
friend declarations. (#GH113324)
936938
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
937-
- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
939+
- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
938940
- Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
939941
- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
940942
- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ QualType Sema::BuildPointerType(QualType T,
18261826
if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
18271827
return QualType();
18281828

1829-
assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
1829+
if (T->isObjCObjectType())
1830+
return Context.getObjCObjectPointerType(T);
18301831

18311832
// In ARC, it is forbidden to build pointers to unqualified pointers.
18321833
if (getLangOpts().ObjCAutoRefCount)
@@ -9806,8 +9807,7 @@ QualType Sema::BuiltinAddPointer(QualType BaseType, SourceLocation Loc) {
98069807
}
98079808

98089809
QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) {
9809-
// We don't want block pointers or ObjectiveC's id type.
9810-
if (!BaseType->isAnyPointerType() || BaseType->isObjCIdType())
9810+
if (!BaseType->isAnyPointerType())
98119811
return BaseType;
98129812

98139813
return BaseType->getPointeeType();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++17 %s
2+
3+
// expected-no-diagnostics
4+
5+
@interface I;
6+
@end
7+
8+
static_assert(__is_same(__add_pointer(id), id*));
9+
static_assert(__is_same(__add_pointer(I), I*));
10+
11+
static_assert(!__is_same(__remove_pointer(id), id));
12+
static_assert(__is_same(__remove_pointer(id*), id));
13+
static_assert(__is_same(__remove_pointer(__add_pointer(id)), id));
14+
static_assert(__is_same(__add_pointer(__remove_pointer(id)), id));

0 commit comments

Comments
 (0)