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
* [Bug c++/107124] Reference template parameter refers to a temporary object
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 ` pinskia at gcc dot gnu.org
2022-10-30 20:50 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 20:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC also invokes the static assert but ICC accepts it.
Note I think clang/ICC get the following wrong too:
template<int>
struct A {};
template<const int & I>
constexpr int f(A<I>) { return 0; }
template<class T>
constexpr int f(T) { return 1; }
const int tt = 0;
static_assert( f(A<tt>{}) == 1 );
I don't think any compiler implements this correct either ...
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/107124] Reference template parameter refers to a temporary object
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
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 20:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is one which GCC/clang agree and accepts but MSVC/ICC reject (even before
the static assert):
template<int>
struct A {};
template<const int & I>
constexpr int f(A<I>) { return 0; }
template<class T>
constexpr int f(T) { return 1; }
const int tt = 0;
static_assert( f<tt>(A<tt>{}) == 0, "" );
---- CUT ----
So it looks like it is more complex than what I even orginally though.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/107124] Reference template parameter refers to a temporary object
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
3 siblings, 0 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2022-10-30 21:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124
--- Comment #3 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
The latter example is indeed a bug in MSVC:
https://developercommunity.visualstudio.com/t/Cannot-find-template-function-with-expli/1672180
And here is the related discussion according the original issue:
https://stackoverflow.com/a/73921590/7325599
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/107124] Reference template parameter refers to a temporary object
2022-10-02 12:23 [Bug c++/107124] New: Reference template parameter refers to a temporary object fchelnokov at gmail dot com
` (2 preceding siblings ...)
2022-10-30 21:10 ` fchelnokov at gmail dot com
@ 2022-10-31 20:54 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-31 20:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107124
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2022-10-31
Status|UNCONFIRMED |NEW
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
^ 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).