public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context
@ 2023-10-28 19:46 falemagn at gmail dot com
  2023-10-29 17:08 ` [Bug c++/112267] " falemagn at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: falemagn at gmail dot com @ 2023-10-28 19:46 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/112267] "inline function constexpr used but never defined" warning in SFINAE context
  2023-10-28 19:46 [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context falemagn at gmail dot com
@ 2023-10-29 17:08 ` falemagn at gmail dot com
  2023-10-29 17:10 ` falemagn at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: falemagn at gmail dot com @ 2023-10-29 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Fabio Alemagna <falemagn at gmail dot com> ---
Changing the return type of the function func() from int to auto makes the
warning disappear.

Incidentally it causes an error on clang, though, which prompts the question:
is this a clang bug, for erroring out, or a gcc bug, for not erroring out?

See it on Compiler Explorer: https://godbolt.org/z/4ETs4ca3d

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/112267] "inline function constexpr used but never defined" warning in SFINAE context
  2023-10-28 19:46 [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context falemagn at gmail dot com
  2023-10-29 17:08 ` [Bug c++/112267] " falemagn at gmail dot com
@ 2023-10-29 17:10 ` falemagn at gmail dot com
  2023-10-29 17:13 ` pinskia at gcc dot gnu.org
  2023-10-29 19:53 ` falemagn at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: falemagn at gmail dot com @ 2023-10-29 17:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Fabio Alemagna <falemagn at gmail dot com> ---
Sorry, "from int to auto" should have been "from bool to auto". You get the
point.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/112267] "inline function constexpr used but never defined" warning in SFINAE context
  2023-10-28 19:46 [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context falemagn at gmail dot com
  2023-10-29 17:08 ` [Bug c++/112267] " falemagn at gmail dot com
  2023-10-29 17:10 ` falemagn at gmail dot com
@ 2023-10-29 17:13 ` pinskia at gcc dot gnu.org
  2023-10-29 19:53 ` falemagn at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-29 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Fabio Alemagna from comment #1)
> Changing the return type of the function func() from int to auto makes the
> warning disappear.
> 
> Incidentally it causes an error on clang, though, which prompts the
> question: is this a clang bug, for erroring out, or a gcc bug, for not
> erroring out?

I tested MSVC also. It errors out with /std:c++20 but not with /std:c++17 so
maybe there was a change for C++20 that clang decided it applies for previous
C++ too (and GCC did not implement that rule yet).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/112267] "inline function constexpr used but never defined" warning in SFINAE context
  2023-10-28 19:46 [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context falemagn at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-29 17:13 ` pinskia at gcc dot gnu.org
@ 2023-10-29 19:53 ` falemagn at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: falemagn at gmail dot com @ 2023-10-29 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Fabio Alemagna <falemagn at gmail dot com> ---
With a tweak(In reply to Andrew Pinski from comment #3)
> (In reply to Fabio Alemagna from comment #1)
> > Changing the return type of the function func() from int to auto makes the
> > warning disappear.
> > 
> > Incidentally it causes an error on clang, though, which prompts the
> > question: is this a clang bug, for erroring out, or a gcc bug, for not
> > erroring out?
> 
> I tested MSVC also. It errors out with /std:c++20 but not with /std:c++17 so
> maybe there was a change for C++20 that clang decided it applies for
> previous C++ too (and GCC did not implement that rule yet).


Making the function a template, while keeping the return type as 'auto', and
making its template parameter depend on the template parameter of the caller,
solves the error and silences the warning on gcc.


Making the return value 'bool', even if the function is a template, still makes
the warning appear.


On Compiler Explorer: https://godbolt.org/z/E5qMT55MW

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-29 19:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-28 19:46 [Bug c++/112267] New: "inline function constexpr used but never defined" warning in SFINAE context falemagn at gmail dot com
2023-10-29 17:08 ` [Bug c++/112267] " falemagn at gmail dot com
2023-10-29 17:10 ` falemagn at gmail dot com
2023-10-29 17:13 ` pinskia at gcc dot gnu.org
2023-10-29 19:53 ` falemagn at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).