<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylVdtu2zgQ_Rr5ZbCGLNlO9KCHXJrWwF6AtkAvLwuKHFlcUKLAS5zu1--QlFPJadBdbCLIvAxnzpyhzjRafKs_dTgAA-uM584bBDsil0zJv5mTegBpQWArBxTgrRyO8OHh8PvNm6y4A9eRtW-sk85H25ZJZQEfyaPrtD920cRbOotPo0Frg5XQaIesuHLAGe0BGwCN0Qa0d1YKBN1OQdZZfp_lN-n9QBb4xPpR4Tl4q5XSpwCKazrHdT9KhZY8iuBsJH-QB-NTJ3kHljApAYff_oAGQfajJkANuStv5oGyfT49aVqUcuDKU4CsvJOamELWZ-WbH23by934HliPdmQc4TNkV7dpEejPIaXDXDzqvo0YDOHXdx9iguf5-4t5Vt7Do5biOUjwlOpH1fpT2U62joW8nncXQZM5VZcTY4N1oTTQaK3gkSmf_LdMWeLldu7ifjH_19B_irK8m45NiQrkKnjIimt6YqZFRSPrRKhUeRMMCOp0kPwHw4qmoQAvjd7PjdIzx_SfuaEcXqcmjC9q_mUZYuLga1y9IPXCR3o_pzRdPciKvR7RMKdNSnpOzsyIRoHPmAh8Sdtfw0bgpagCAIP0zQ8BU8CxjCsHBz2Tw8TcBG2GNunBx0jKrGg_KMECHR2avpJi__PqLdEvjoRTC2Knw5y-_eTvc1q4vG-vw3lB1xQwTuIVeFnpS72I77ecf9cj6aIkBckiEfTKkTqNLqjTZg2HFg5AUhW3yctFafd50l-Z1HiICkmrs_sVQgfgilE56MPVMBotPA9KGIZHQ_chSeBZFTcLaT0Qd74nbkg2g3ST5ktr6bqfQnNIZY7exTknAa3RPVjtDSE4gG4ciz0iLr-V7p1vzirtkPg8IbUWoQec3H0iQhr9tF6JuhRVWbEV89QzTP1R91QLaVfeqLpzbrSB_OKBnqN0nW_WBIEmSj2ef36hHP9C7mgaYVsa7Mpym6-6uqyaptrRf5VfCaxazq73ZVlVRcOLdrNnK8UaVLbOdrdZUQx4SpnTONvdr_4_AlkXeVHkm2Kzudptd5t1W25LwpDzzfY6z1mZbXOkr0ytg5-1NseVqaPLxh8tbSppnf2-yahlHQfECJgQUu9VWJMCEPzbqW2-0odnLZgKPGjSYaWoh5oexSrCriPmfwC_a3qA>53340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
C++ SFINAE fails even though the expression is not ill formed
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Tomeamis
</td>
</tr>
</table>
<pre>
When a structure specialization is defined using SFINAE, the substitution fails even though the used expression doesn't cause an error outside of SFINAE.
For example, the following code compiles and outputs 0, which should IMO be impossible:
```
#include <iostream>
#include <sstream>
namespace X {
template <typename LHS, typename RHS, typename = void>
struct is_lshiftable
{
static constexpr bool value = false;
};
template <typename LHS, typename RHS>
struct is_lshiftable<LHS, RHS, decltype((void)(std::declval<LHS>()<<std::declval<RHS>()))>
{
static constexpr bool value = true;
};
}
namespace Y {
struct Z {};
}
std::ostream &operator<<(std::ostream &str, const Y::Z &val) {return str;}
int main()
{
using T = decltype(std::declval<std::ostringstream&>()<<std::declval<const Y::Z&>());
std::cout<<X::is_lshiftable<std::ostringstream&, const Y::Z&>::value;
}
```
Gcc compiles it and the result ouptuts 1. If I put the `operator<<` definition inside `namespace Y`, clang also produces a program which outputs 1.
I stumbled on this issue when using clangd compiled from source I obtained from GitHub, the test were done using Wandbox.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVclu2zAQ_Rr5MqghS7YcH3TI0rQGugBtgC6XghJHFgtKFLjEab--Q1JOJadBW4OQuQxn3rwhHyvFf5SfWuyBgbHa1dZpBDNgLZgUP5kVqgdhgGMjeuTgjOgP8PF2_-7yZZJdg23J2lXGCuuCbcOENID35NG2yh3aYOIM7cWHQaMx3oorNH2SbS3UjNaA9YBaKw3KWSM4gmrGIMskvUnSy_i9JQt8YN0g8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