Author: Yihan Wang Date: 2026-07-02T23:37:59+08:00 New Revision: fc1565f89eaff7b4594186793cbb04862660ecff
URL: https://github.com/llvm/llvm-project/commit/fc1565f89eaff7b4594186793cbb04862660ecff DIFF: https://github.com/llvm/llvm-project/commit/fc1565f89eaff7b4594186793cbb04862660ecff.diff LOG: [clang] Check `T` and `U` operands of __reference_constructs_from_temporary are complete types (#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. --------- Signed-off-by: yronglin <[email protected]> Added: Modified: clang/lib/Sema/SemaTypeTraits.cpp clang/test/SemaCXX/type-traits-incomplete.cpp Removed: ################################################################################ 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..2e09d60eecd81 100644 --- a/clang/test/SemaCXX/type-traits-incomplete.cpp +++ b/clang/test/SemaCXX/type-traits-incomplete.cpp @@ -1,6 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -struct S; // expected-note 6 {{forward declaration of 'S'}} +struct S; // expected-note 8 {{forward declaration of 'S'}} + +struct NoConv {}; +struct Bad { template<class T> Bad(T v) noexcept(noexcept(member_ = v)) {} int member_; }; void f() { __is_pod(S); // expected-error{{incomplete type 'S' used in type trait expression}} @@ -11,4 +14,7 @@ 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}} + + static_assert(!__reference_constructs_from_temporary(S, NoConv&&)); // expected-error{{incomplete type 'S' used in type trait expression}} + static_assert(!__reference_constructs_from_temporary(Bad, S)); // expected-error{{incomplete type 'S' used in type trait expression}} } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
