public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107124] New: Reference template parameter refers to a temporary object
@ 2022-10-02 12:23 fchelnokov at gmail dot com
  2022-10-30 20:47 ` [Bug c++/107124] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2022-10-02 12:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107124
           Summary: Reference template parameter refers to a temporary
                    object
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program is accepted by Clang:

template<int>
struct A {};

template<const int & I>
constexpr int f(A<I>) { return 0; }

template<class T>
constexpr int f(T) { return 1; }

static_assert( f(A<0>{}) == 1 );

But in GCC static assertion fails, because f(A<I>) overload is preferred.
Online demo: https://gcc.godbolt.org/z/9hj4WoT7b

But this is illegal by http://eel.is/c++draft/temp.arg.nontype#3.1, since const
int & I cannot refer to a temporary int 0.

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

end of thread, other threads:[~2022-10-31 20:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 12:23 [Bug c++/107124] New: Reference template parameter refers to a temporary object fchelnokov at gmail dot com
2022-10-30 20:47 ` [Bug c++/107124] " pinskia at gcc dot gnu.org
2022-10-30 20:50 ` pinskia at gcc dot gnu.org
2022-10-30 21:10 ` fchelnokov at gmail dot com
2022-10-31 20:54 ` mpolacek at gcc dot gnu.org

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).