https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102980

            Bug ID: 102980
           Summary: Fail to get an r-value from std::array::size in a
                    template function
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davide.gadioli at polimi dot it
  Target Milestone: ---

System configuration:
Ubuntu 20.04
gcc 11.2.0 built from sources, configured with the following line ../configure
--prefix=/opt/modules/install/gcc/11.2.0 --enable-gold=yes  --enable-lto
--disable-multilib --enable-languages=c,c++,fortran

I compiled the snippet of code with the following flags: -Wall -Wextra
-fno-strict-aliasing -fwrapv

Problem:
while compiling the following snippet of code:

#include<array>

template<class T>
auto parse() {
    const std::array<int, 3> array{0, 1 , 2};
    return std::size_t{array.size()};
}

gcc fails to compile and it generates the following compiler error:

```
test.cpp: In function ‘auto parse()’:
test.cpp:6:34: error: no matching function for call to ‘std::array<int,
3>::size(const std::array<int, 3>*)’
    6 |     return std::size_t{array.size()};
      |                        ~~~~~~~~~~^~
In file included from test.cpp:1:
/opt/modules/install/gcc/11.2.0/include/c++/11.2.0/array:176:7: note:
candidate: ‘constexpr std::array<_Tp, _Nm>::size_type std::array<_Tp,
_Nm>::size() const [with _Tp = int; long unsigned int _Nm = 3; std::array<_Tp,
_Nm>::size_type = long unsigned int]’
  176 |       size() const noexcept { return _Nm; }
      |       ^~~~
/opt/modules/install/gcc/11.2.0/include/c++/11.2.0/array:176:7: note:  
candidate expects 0 arguments, 1 provided
```

It seems that it cannot recognize "this" when calling the function. However, I
can't pinpoint the exact cause of the problem. Maybe is related to Bug 101680 .

By using Compiler Explorer (https://godbolt.org/z/ehv37scv4) it seems that the
same behavior happens for gcc 10, but not for gcc 9.

The snippet of code has been revised from my initial post on stack overflow
(https://stackoverflow.com/q/69742093/2481512) using user feedback

Reply via email to