[clang] [clang] Check precondition of __reference_constructs_from_temporary (PR #206703)
Yihan Wang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 30 03:36:38 PDT 2026
https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/206703
This PR fix a bug introduce by https://github.com/llvm/llvm-project/pull/206527.
[type.traits] Precondition : "T and U shall be complete types, cv void, or arrays of unknown bound first.
The check for which [#206527](https://github.com/llvm/llvm-project/pull/206527.) disables if the first argument isn't a reference type.
>From c9e3e6194e58b65a611bad3e356119495ffb5e12 Mon Sep 17 00:00:00 2001
From: yronglin <yronglin777 at gmail.com>
Date: Tue, 30 Jun 2026 03:02:51 -0700
Subject: [PATCH] [clang] Check precondition of
__reference_constructs_from_temporary
Signed-off-by: yronglin <yronglin777 at gmail.com>
---
clang/lib/Sema/SemaTypeTraits.cpp | 5 ++---
clang/test/SemaCXX/type-traits-incomplete.cpp | 6 ++++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 4de73601e273d..e3ae6095c846c 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -1292,8 +1292,6 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
Kind == clang::BTT_ReferenceBindsToTemporary ||
Kind == clang::BTT_ReferenceConstructsFromTemporary ||
Kind == clang::BTT_ReferenceConvertsFromTemporary;
- if (UseRawObjectType && !Args[0]->getType()->isReferenceType())
- return false;
// Precondition: T and all types in the parameter pack Args shall be
// complete types, (possibly cv-qualified) void, or arrays of
@@ -1310,7 +1308,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
// Make sure the first argument is not incomplete nor a function type.
QualType T = Args[0]->getType();
- if (T->isIncompleteType() || T->isFunctionType())
+ if (T->isIncompleteType() || T->isFunctionType() ||
+ (UseRawObjectType && !T->isReferenceType()))
return false;
// Make sure the first argument is not an abstract type.
diff --git a/clang/test/SemaCXX/type-traits-incomplete.cpp b/clang/test/SemaCXX/type-traits-incomplete.cpp
index 3e341d6482440..2f56b5fa81820 100644
--- a/clang/test/SemaCXX/type-traits-incomplete.cpp
+++ b/clang/test/SemaCXX/type-traits-incomplete.cpp
@@ -12,3 +12,9 @@ void f() {
__is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used in type trait expression}}
__is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
}
+
+struct NoConv;
+struct Bad;
+
+constexpr bool a = __reference_constructs_from_temporary(S, NoConv&&); // expected-error{{incomplete type 'Bad' used in type trait expression}}
+
More information about the cfe-commits
mailing list