https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110139
Bug ID: 110139
Summary: [libstdc++] Ambiguous use of [] operator for 0-sized
arrays (with clang)
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: joseph.faulls at imgtec dot com
Target Milestone: ---
Created attachment 55269
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55269&action=edit
Preprocessed test
Hi,
This issue only happens when clang uses the array headers on a 32-bit platform.
It's entirely possible that clang itself is the issue, so apologies if this bug
report is unsuitable. With a similar test case (attached as
similar_test_case.cpp), GCC does give me a warning. See bottom of this bug
report for test case and error.
What I think is happening:
By defining the * operator for the _Type of struct __array_traits<_Tp, 0> we
bring in the built-in [] operator for the type we offset by. For example,
offsetting by an integer, the overload resolution sees both the built in
operator `operator[](int *, int)` and the defined [] operator for _Type `_Tp&
operator[](size_t) const noexcept { __builtin_trap(); }`. The reason this only
happens on 32-bit platforms is because the offset type size would match the
size_t.
test.cpp:
#include <array>
template class std::array<int, 0> ;
Error:
include/c++/13.1.0/array:243:9: error: use of overloaded operator '[]' is
ambiguous (with operand types 'typename __array_traits<int, 0U>::_Type' and
'int')
return _M_elems[0];
^~~~~~~~ ~
test.cpp:3:21: note: in instantiation of member function 'std::array<int,
0>::front' requested here
template class std::array<int, 0> ;
^
include/c++/13.1.0/array:68:13: note: candidate function
_Tp& operator[](size_t) const noexcept { __builtin_trap(); }
^
include/c++/13.1.0/array:243:9: note: built-in candidate operator[](int *, int)
return _M_elems[0];
^
include/c++/13.1.0/array:243:9: note: built-in candidate operator[](const int
*, int)
include/c++/13.1.0/array:243:9: note: built-in candidate operator[](volatile
int *, int)
include/c++/13.1.0/array:243:9: note: built-in candidate operator[](const
volatile int *, int)