https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532
--- Comment #29 from Andrey Alekseenko <gcc-bugzilla at al42and dot me> ---
> it seems like we should treat *any* class with a reference member as a
> reference wrapper.
And any class with a pointer, I suspect.
This is a reduced/simplified example from our codebase still triggering the
error even with 59bfdd5f467292a368d0d628084a4b65d1bb06bb:
$ cat test.cpp
struct ArrayRef
{
ArrayRef(int* ptr) : ptr_(ptr) {}
int& operator[](int n) const { return ptr_[n]; }
int* ptr_;
};
int main()
{
int a;
const int& r = ArrayRef(&a)[0];
}
$ g++ -std=c++17 -Wdangling-reference test.cpp -o test
test.cpp: In function ‘int main()’:
test.cpp:11:16: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
11 | const int& r = ArrayRef(&a)[0];
| ^
test.cpp:11:34: note: the temporary was destroyed at the end of the full
expression ‘ArrayRef((& a)).ArrayRef::operator[](0)’
11 | const int& r = ArrayRef(&a)[0];
| ^