Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Clang] __has_unique_object_representations should not accept Incomplete[] #138291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented May 2, 2025

This implements LWG4113

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

…ete[]

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 to day is in a world of hurt.

Fixes llvm#118350
@cor3ntin cor3ntin requested review from AaronBallman and erichkeane and removed request for AaronBallman May 2, 2025 15:08
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 2, 2025
@llvmbot
Copy link
Member

llvmbot commented May 2, 2025

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

This implements LWG4113

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


Full diff: https://github.com/llvm/llvm-project/pull/138291.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/lib/Sema/SemaExprCXX.cpp (+9-5)
  • (modified) clang/test/SemaCXX/type-traits.cpp (+10)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 95e0574562a2d..5a9f5edfcf9ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -547,6 +547,9 @@ Bug Fixes to Compiler Builtins
   ``void(char *, char *)`` to ``void(void *, void *)`` to match GCC's signature
   for the same builtin. (#GH47833)
 
+- ``__has_unique_object_representations(Incomplete[])`` is no longer accepted, per
+  `LWG4113 <https://cplusplus.github.io/LWG/issue4113>`_.
+
 Bug Fixes to Attribute Support
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  - Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ee45e196bdb5d..d1121a605dbbd 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5418,6 +5418,15 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
     return !S.RequireCompleteType(
         Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 
+  // has_unique_object_representations<T>
+  // remove_all_extents_t<T> shall be a complete type or cv void (LWG4113).
+  case UTT_HasUniqueObjectRepresentations:
+    ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0);
+    if (ArgTy->isVoidType())
+      return true;
+    return !S.RequireCompleteType(
+        Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t<T> shall be a complete type or cv void.
   case UTT_IsTrivial:
@@ -5445,13 +5454,8 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
   case UTT_HasTrivialCopy:
   case UTT_HasTrivialDestructor:
   case UTT_HasVirtualDestructor:
-  // has_unique_object_representations<T> when T is an array is defined in terms
-  // of has_unique_object_representations<remove_all_extents_t<T>>, so the base
-  // type needs to be complete even if the type is an incomplete array type.
-  case UTT_HasUniqueObjectRepresentations:
     ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0);
     [[fallthrough]];
-
   // C++1z [meta.unary.prop]:
   //   T shall be a complete type, cv void, or an array of unknown bound.
   case UTT_IsDestructible:
diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp
index b130024503101..7768f61ac2d00 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3383,6 +3383,16 @@ static_assert(!__has_unique_object_representations(float), "definitely not Float
 static_assert(!__has_unique_object_representations(double), "definitely not Floating Point");
 static_assert(!__has_unique_object_representations(long double), "definitely not Floating Point");
 
+
+static_assert(!__has_unique_object_representations(AnIncompleteType[]));
+//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
+static_assert(!__has_unique_object_representations(AnIncompleteType[][1]));
+//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
+static_assert(!__has_unique_object_representations(AnIncompleteType[1]));
+//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
+static_assert(!__has_unique_object_representations(AnIncompleteType));
+//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}}
+
 struct NoPadding {
   int a;
   int b;

@cor3ntin cor3ntin merged commit e59ed0f into llvm:main May 2, 2025
15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ete[] (llvm#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 llvm#118350
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ete[] (llvm#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 llvm#118350
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ete[] (llvm#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 llvm#118350
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…ete[] (llvm#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 llvm#118350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LWG4113: Disallow has_unique_object_representations<Incomplete[]>
3 participants