Skip to content
Snippets Groups Projects
Commit 0b2f34ca authored by Simon Martin's avatar Simon Martin
Browse files

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.
parent fcecc74c
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment