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

            Bug ID: 118632
           Summary: 0 vs nullptr mixup in template
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pobrn at protonmail dot com
  Target Milestone: ---

Consider the following piece of code:

    #include <type_traits>

    template <typename T, std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
    class Matrix {};

    template <typename T> void operator*(Matrix<T>, int rgb) {
        Matrix<int>{} * rgb;
    }


-- https://gcc.godbolt.org/z/GTqMf69K4

It fails on gcc 15 with the following error:

    <source>: In function 'void operator*(Matrix<T>, int)':
    <source>:7:17: error: no match for 'operator*' (operand types are
'Matrix<int>' and 'int') [-Wtemplate-body]
        7 |   Matrix<int>{} * rgb;
        |   ~~~~~~~~~~~~~~^~~~~
    <source>:7:17: note: there is 1 candidate
    <source>:6:28: note: candidate 1: 'template<class T> void
operator*(Matrix<T>, int)'
        6 | template <typename T> void operator*(Matrix<T>, int rgb) {
        |                            ^~~~~~~~
    <source>:6:28: note: template argument deduction/substitution failed:
    <source>:7:19: note:   template argument '0' does not match 'nullptr'
        7 |   Matrix<int>{} * rgb;
        |                   ^~~

This does not happen with clang, msvc, or earlier gcc versions.

Reply via email to