Skip to content

Commit 98e674c

Browse files
authored
[clang] Non-object types are non-trivially relocatable (#69734)
Both active C++ proposals (P1144 and P2786) agree that `is_trivially_relocatable_v<int&>` and `is_trivially_relocatable_v<int()>` should be false, not true. Only complete object types can be trivially relocatable. Fixes #67498
1 parent badec9b commit 98e674c

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ Bug Fixes in This Version
637637
- Fix crash during code generation of C++ coroutine initial suspend when the return
638638
type of await_resume is not trivially destructible.
639639
Fixes (`#63803 <https://github.com/llvm/llvm-project/issues/63803>`_)
640+
- ``__is_trivially_relocatable`` no longer returns true for non-object types
641+
such as references and functions.
642+
Fixes (`#67498 <https://github.com/llvm/llvm-project/issues/67498>`_)
640643
- Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members
641644
which are not member functions.
642645
- Support UDLs in ``static_assert`` message.

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
26492649

26502650
if (BaseElementType->isIncompleteType()) {
26512651
return false;
2652+
} else if (!BaseElementType->isObjectType()) {
2653+
return false;
26522654
} else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
26532655
return RD->canPassInRegisters();
26542656
} else {
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
22

3-
struct S; // expected-note 2 {{forward declaration of 'S'}}
3+
struct S; // expected-note 6 {{forward declaration of 'S'}}
44

55
void f() {
66
__is_pod(S); // expected-error{{incomplete type 'S' used in type trait expression}}
77
__is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
8+
9+
__is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in type trait expression}}
10+
__is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
11+
12+
__is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used in type trait expression}}
13+
__is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
814
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
3+
4+
// expected-no-diagnostics
5+
6+
static_assert(!__is_pod(void), "");
7+
static_assert(!__is_pod(int&), "");
8+
static_assert(!__is_pod(int()), "");
9+
10+
static_assert(!__is_trivially_copyable(void), "");
11+
static_assert(!__is_trivially_copyable(int&), "");
12+
static_assert(!__is_trivially_copyable(int()), "");
13+
14+
static_assert(!__is_trivially_relocatable(void), "");
15+
static_assert(!__is_trivially_relocatable(int&), "");
16+
static_assert(!__is_trivially_relocatable(int()), "");

0 commit comments

Comments
 (0)