public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110139] New: [libstdc++] Ambiguous use of [] operator for 0-sized arrays (with clang)
@ 2023-06-06  9:18 joseph.faulls at imgtec dot com
  2023-06-06  9:18 ` [Bug libstdc++/110139] " joseph.faulls at imgtec dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: joseph.faulls at imgtec dot com @ 2023-06-06  9:18 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-06-06 13:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06  9:18 [Bug libstdc++/110139] New: [libstdc++] Ambiguous use of [] operator for 0-sized arrays (with clang) joseph.faulls at imgtec dot com
2023-06-06  9:18 ` [Bug libstdc++/110139] " joseph.faulls at imgtec dot com
2023-06-06 10:26 ` [Bug libstdc++/110139] [13/14 Regression] " redi at gcc dot gnu.org
2023-06-06 10:30 ` redi at gcc dot gnu.org
2023-06-06 10:44 ` joseph.faulls at imgtec dot com
2023-06-06 11:02 ` redi at gcc dot gnu.org
2023-06-06 11:02 ` redi at gcc dot gnu.org
2023-06-06 11:45 ` cvs-commit at gcc dot gnu.org
2023-06-06 13:34 ` cvs-commit at gcc dot gnu.org
2023-06-06 13:34 ` redi 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).