Skip to content

Commit e59ed0f

Browse files
authored
[Clang] __has_unique_object_representations should not accept Incomplete[] (#138291)
This implements [LWG4113](https://cplusplus.github.io/LWG/issue411) This is technically a breaking change, but it's a fix, and I think anyone who relies on this today is in a world of hurt. Fixes #118350
1 parent aa61377 commit e59ed0f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ Bug Fixes to Compiler Builtins
559559
``void(char *, char *)`` to ``void(void *, void *)`` to match GCC's signature
560560
for the same builtin. (#GH47833)
561561

562+
- ``__has_unique_object_representations(Incomplete[])`` is no longer accepted, per
563+
`LWG4113 <https://cplusplus.github.io/LWG/issue4113>`_.
564+
562565
Bug Fixes to Attribute Support
563566
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
564567
- Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5418,6 +5418,15 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
54185418
return !S.RequireCompleteType(
54195419
Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
54205420

5421+
// has_unique_object_representations<T>
5422+
// remove_all_extents_t<T> shall be a complete type or cv void (LWG4113).
5423+
case UTT_HasUniqueObjectRepresentations:
5424+
ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0);
5425+
if (ArgTy->isVoidType())
5426+
return true;
5427+
return !S.RequireCompleteType(
5428+
Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
5429+
54215430
// C++1z [meta.unary.prop]:
54225431
// remove_all_extents_t<T> shall be a complete type or cv void.
54235432
case UTT_IsTrivial:
@@ -5445,13 +5454,8 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
54455454
case UTT_HasTrivialCopy:
54465455
case UTT_HasTrivialDestructor:
54475456
case UTT_HasVirtualDestructor:
5448-
// has_unique_object_representations<T> when T is an array is defined in terms
5449-
// of has_unique_object_representations<remove_all_extents_t<T>>, so the base
5450-
// type needs to be complete even if the type is an incomplete array type.
5451-
case UTT_HasUniqueObjectRepresentations:
54525457
ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0);
54535458
[[fallthrough]];
5454-
54555459
// C++1z [meta.unary.prop]:
54565460
// T shall be a complete type, cv void, or an array of unknown bound.
54575461
case UTT_IsDestructible:

clang/test/SemaCXX/type-traits.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,16 @@ static_assert(!__has_unique_object_representations(float), "definitely not Float
33833383
static_assert(!__has_unique_object_representations(double), "definitely not Floating Point");
33843384
static_assert(!__has_unique_object_representations(long double), "definitely not Floating Point");
33853385

3386+
3387+
static_assert(!__has_unique_object_representations(AnIncompleteType[]));
3388+
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
3389+
static_assert(!__has_unique_object_representations(AnIncompleteType[][1]));
3390+
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
3391+
static_assert(!__has_unique_object_representations(AnIncompleteType[1]));
3392+
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
3393+
static_assert(!__has_unique_object_representations(AnIncompleteType));
3394+
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
3395+
33863396
struct NoPadding {
33873397
int a;
33883398
int b;

0 commit comments

Comments
 (0)