https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118282

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>:

https://gcc.gnu.org/g:0b2f34ca19edf2b033c90ff378f561429b82a77a

commit r15-7416-g0b2f34ca19edf2b033c90ff378f561429b82a77a
Author: Simon Martin <si...@nasilyan.com>
Date:   Fri Feb 7 15:00:14 2025 +0100

    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.
  • [Bug c++/118282] [12/13/14/15 R... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to