On 7 Feb 2025, at 14:17, Jason Merrill wrote: > On 2/7/25 4:41 AM, Simon Martin wrote: >> We've been rejecting the following valid code since GCC 4 >> >> === cut here === >> struct A { >> explicit A (int); >> operator void* () const; >> }; >> void foo (const A& x) { >> auto res = 0 ? x : 0; >> } >> int main () { >> A a{5}; >> foo(a); >> } >> === cut here === >> >> The problem is that for COND_EXPR, add_builtin_candidate has an early >> return if the true and false values are not pointers that does not take >> null pointer constants into account. This causes to not find any valid >> conversion, and fail to compile. >> >> This patch fixes the condition to also pass if the true/false values are >> not pointers but null pointer constants, which resolves the PR. >> >> Successfully tested on x86_64-pc-linux-gnu. Given this regression's age, >> I don't think it make much sense to fix it during stage 4 (let me know >> if you disagree), so OK for GCC16? > > This looks safe enough, OK for GCC 15. Cool, thanks. Merged as r15-7416-g0b2f34ca19edf2.
Simon