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

            Bug ID: 112267
           Summary: "inline function constexpr used but never defined"
                    warning in SFINAE context
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: falemagn at gmail dot com
  Target Milestone: ---

I am expecting no warnings from the following code snippets, especially because
SFINAE is being correctly triggered, and indeed clang doesn't provide one for
the specific case at hand, alas g++ does.

I am left wondering whether this is a bug or a "overreaction". The warning
itself cannot be turned off with a pragma.

    #if defined(__clang__)
        _Pragma("GCC diagnostic ignored \"-Wundefined-inline\"");       
    #endif

    #define DEFINE_FUNC 0

    constexpr bool func()
    #if DEFINE_FUNC
    {
        return true;
    }
    #else
    ;
    #endif

    template <int Dummy = 0, bool = func()>
    constexpr bool is_defined(int) {
        return true;
    }


    template <int Dummy = 0>
    constexpr bool is_defined(double) {
        return false;
    }

    int a = is_defined(0);

See it working on Compiler Explorer: https://godbolt.org/z/dvTKdGfbv

Reply via email to