https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107065
Bug ID: 107065
Summary: GCC treats rvalue like lvalue
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
In the following program gcc incorrectly treats the expression `!(!b)` as
lvalue. Demo: https://godbolt.org/z/zv5En5hjG
```
#include <iostream>
template<typename T>
struct value_category {
// Or can be an integral or enum value
static constexpr auto value = "prvalue";
};
template<typename T>
struct value_category<T&> {
static constexpr auto value = "lvalue";
};
template<typename T>
struct value_category<T&&> {
static constexpr auto value = "xvalue";
};
// Double parens for ensuring we inspect an expression,
// not an entity
#define VALUE_CATEGORY(expr) value_category<decltype((expr))>::value
int main() {
bool b = true;
std::cout << VALUE_CATEGORY(!(!b)); //gcc wrongly prints lvalue
}
```