public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator
@ 2024-02-06 20:27 Mark_B53 at yahoo dot com
2024-02-06 20:48 ` [Bug c++/113791] " mpolacek at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Mark_B53 at yahoo dot com @ 2024-02-06 20:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
Bug ID: 113791
Summary: Incorrect handling of lvalue to rvalue conversion in
ternary operator
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Mark_B53 at yahoo dot com
Target Milestone: ---
#include <unordered_map>
#include <iostream>
template<template<class, class, class...> class Map, typename Key, typename T,
typename KeyP, typename... Args>
T getMapEntry(const Map<Key, T, Args...>& map, const KeyP& key, T&& defval) {
static_assert(std::is_convertible_v<KeyP, Key>);
auto i = map.find(key);
return i != map.end() ? i->second : std::move(defval);
}
class Foo {
public:
Foo() { std::cout << __PRETTY_FUNCTION__ << '\n'; }
~Foo() { std::cout << __PRETTY_FUNCTION__ << '\n'; }
Foo(const Foo&) { std::cout << __PRETTY_FUNCTION__ << '\n'; }
Foo& operator=(const Foo&) { std::cout << __PRETTY_FUNCTION__ << '\n';
return *this; }
Foo(Foo&&) { std::cout << __PRETTY_FUNCTION__ << '\n'; }
Foo& operator=(Foo&&) { std::cout << __PRETTY_FUNCTION__ << '\n'; return
*this; }
};
int main() {
std::unordered_map<int, Foo> map;
auto&& ret = getMapEntry(map, 123U, Foo{});
return 0;
}
GCC outputs:
Foo::Foo()
Foo::Foo(Foo&&)
Foo::~Foo()
Foo::~Foo()
Correct output:
Foo::Foo()
Foo::Foo(const Foo &)
Foo::~Foo()
Foo::~Foo()
Posted on https://stackoverflow.com/questions/77948860/
Maybe related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
@ 2024-02-06 20:48 ` mpolacek at gcc dot gnu.org
2024-02-06 21:42 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 20:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
Keywords| |needs-reduction
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-02-06
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed. Not a regression AFAICS.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
2024-02-06 20:48 ` [Bug c++/113791] " mpolacek at gcc dot gnu.org
@ 2024-02-06 21:42 ` mpolacek at gcc dot gnu.org
2024-02-07 0:33 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-reduction |rejects-valid
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
template <typename> struct remove_reference;
template <typename _Tp> struct remove_reference<_Tp &> {
typedef _Tp type;
};
template <typename _Tp> typename remove_reference<_Tp>::type &&move(_Tp &&);
template <typename _T2> struct pair {
_T2 second;
};
struct Foo {
Foo();
Foo(const Foo &);
Foo(Foo &&) = delete;
};
struct _Node_const_iterator {
const pair<Foo> *operator->();
};
template <typename, typename, typename = int> struct unordered_map {
_Node_const_iterator find(int);
};
bool b;
template <template <class, class, class> class Map, typename... Args>
void getMapEntry(Map<Args...> map, int key, Foo defval) {
auto i = map.find(key);
b ? i->second : move(defval);
}
int main() {
unordered_map<int, int> map;
getMapEntry(map, 3, {});
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
2024-02-06 20:48 ` [Bug c++/113791] " mpolacek at gcc dot gnu.org
2024-02-06 21:42 ` mpolacek at gcc dot gnu.org
@ 2024-02-07 0:33 ` pinskia at gcc dot gnu.org
2024-02-07 0:35 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-07 0:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Little more reduced:
```
struct Foo {
Foo();
Foo(const Foo &);
Foo(Foo &&) = delete;
};
Foo &&pp();
void f(const Foo b) {
true ? b : pp();
}
```
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
` (2 preceding siblings ...)
2024-02-07 0:33 ` pinskia at gcc dot gnu.org
@ 2024-02-07 0:35 ` pinskia at gcc dot gnu.org
2024-02-15 17:44 ` mpolacek at gcc dot gnu.org
2024-02-15 17:56 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-07 0:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=102251,
| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=87605
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
related to PR 87605 and PR 102251
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
` (3 preceding siblings ...)
2024-02-07 0:35 ` pinskia at gcc dot gnu.org
@ 2024-02-15 17:44 ` mpolacek at gcc dot gnu.org
2024-02-15 17:56 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-15 17:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looking. It's https://cplusplus.github.io/CWG/issues/1895.html which we don't
implement yet.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/113791] Incorrect handling of lvalue to rvalue conversion in ternary operator
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
` (4 preceding siblings ...)
2024-02-15 17:44 ` mpolacek at gcc dot gnu.org
@ 2024-02-15 17:56 ` mpolacek at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-15 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113791
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Stage 1 work. Putting this aside for GCC 15.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-02-15 17:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 20:27 [Bug c++/113791] New: Incorrect handling of lvalue to rvalue conversion in ternary operator Mark_B53 at yahoo dot com
2024-02-06 20:48 ` [Bug c++/113791] " mpolacek at gcc dot gnu.org
2024-02-06 21:42 ` mpolacek at gcc dot gnu.org
2024-02-07 0:33 ` pinskia at gcc dot gnu.org
2024-02-07 0:35 ` pinskia at gcc dot gnu.org
2024-02-15 17:44 ` mpolacek at gcc dot gnu.org
2024-02-15 17:56 ` 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).