-
- Downloads
c++: Properly support null pointer constants in conditional operators [PR118282]
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. PR c++/118282 gcc/cp/ChangeLog: * call.cc (add_builtin_candidate): Also check for null_ptr_cst_p operands. gcc/testsuite/ChangeLog: * g++.dg/conversion/op8.C: New test.
Loading
Please register or sign in to comment