llvm-project
aba63c57 - [clang] The `__reference_meows_from_temporary` builtins should SFINAE friendly when the 1st type is not a reference type (#206527)

Commit
27 days ago
[clang] The `__reference_meows_from_temporary` builtins should SFINAE friendly when the 1st type is not a reference type (#206527) Suppose that `__reference_constructs_from_temporary` is defined as: ```cpp __reference_constructs_from_temporary(_Tp, _Up); ``` A non-reference type can never bind to a temporary, so the result is always `false` for such a `_Tp`. We should short-circuit before reaching the instantiations by check the type of `_Tp`. But clang's `__reference_constructs_from_temporary` eagerly instantiates the construction of `_Up` (including the element's constructor exception specification) even when `_Tp` is not a reference, which can hard-error on misbehaved types. The following code should be accepted, but clang raise a hard error: ```cpp struct NoConv {}; struct Bad { template<class T> Bad(T v) noexcept(noexcept(member_ = v)) {} int member_; }; static_assert(!__reference_constructs_from_temporary(Bad, NoConv&&)); static_assert(!__reference_converts_from_temporary(Bad, NoConv&&)); static_assert(!__reference_binds_to_temporary(Bad, NoConv&&)); ``` The PR refine the implementation of these builtins by short-circuits on a non-reference first operand. Fixes https://github.com/llvm/llvm-project/issues/206524. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
Author
Parents
Loading