[clang] [clang] Check`T` and `U` operands of __reference_constructs_from_temporary are complete types (PR #206703)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 30 03:41:49 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Yihan Wang (yronglin)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/206703.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaTypeTraits.cpp (+2-3)
- (modified) clang/test/SemaCXX/type-traits-incomplete.cpp (+6)
``````````diff
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}}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/206703
More information about the cfe-commits
mailing list