public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function
@ 2021-10-28  7:28 davide.gadioli at polimi dot it
  2021-10-28  8:23 ` [Bug c++/102980] [10/11/12 Regression] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: davide.gadioli at polimi dot it @ 2021-10-28  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
@ 2021-10-28  8:23 ` rguenth at gcc dot gnu.org
  2021-10-28  8:51 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-28  8:23 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Fail to get an r-value from |[10/11/12 Regression] Fail
                   |std::array::size in a       |to get an r-value from
                   |template function           |std::array::size in a
                   |                            |template function
           Keywords|                            |rejects-valid
   Target Milestone|---                         |10.4

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
  2021-10-28  8:23 ` [Bug c++/102980] [10/11/12 Regression] " rguenth at gcc dot gnu.org
@ 2021-10-28  8:51 ` pinskia at gcc dot gnu.org
  2021-10-28  9:32 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-28  8:51 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
      Known to fail|                            |10.1.0
      Known to work|                            |9.1.0, 9.4.0
           Keywords|                            |needs-bisection
   Last reconfirmed|                            |2021-10-28
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed reduced self contained (no header) testcase:
struct a
{
  constexpr int size(void){return 0;}
};

template<class T>
int parse1() {
    a b;
    return int{b.size()};
}

Note the constexpr is important here.

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
  2021-10-28  8:23 ` [Bug c++/102980] [10/11/12 Regression] " rguenth at gcc dot gnu.org
  2021-10-28  8:51 ` pinskia at gcc dot gnu.org
@ 2021-10-28  9:32 ` redi at gcc dot gnu.org
  2021-10-29 17:20 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-28  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started with r10-7096

c++: Fix convert_like in template [PR91465, PR93870, PR92031, PR94068]

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
                   ` (2 preceding siblings ...)
  2021-10-28  9:32 ` redi at gcc dot gnu.org
@ 2021-10-29 17:20 ` mpolacek at gcc dot gnu.org
  2021-11-05 13:42 ` rguenth at gcc dot gnu.org
  2022-03-18 12:16 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-10-29 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
                   ` (3 preceding siblings ...)
  2021-10-29 17:20 ` mpolacek at gcc dot gnu.org
@ 2021-11-05 13:42 ` rguenth at gcc dot gnu.org
  2022-03-18 12:16 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-05 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/102980] [10/11/12 Regression] Fail to get an r-value from std::array::size in a template function
  2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
                   ` (4 preceding siblings ...)
  2021-11-05 13:42 ` rguenth at gcc dot gnu.org
@ 2022-03-18 12:16 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-18 12:16 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |DUPLICATE
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Looks like PR104565, which has recently been fixed on trunk, is a dup of this
PR.  So I guess let's instead mark this PR a dup of that one.

*** This bug has been marked as a duplicate of bug 104565 ***

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

end of thread, other threads:[~2022-03-18 12:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28  7:28 [Bug c++/102980] New: Fail to get an r-value from std::array::size in a template function davide.gadioli at polimi dot it
2021-10-28  8:23 ` [Bug c++/102980] [10/11/12 Regression] " rguenth at gcc dot gnu.org
2021-10-28  8:51 ` pinskia at gcc dot gnu.org
2021-10-28  9:32 ` redi at gcc dot gnu.org
2021-10-29 17:20 ` mpolacek at gcc dot gnu.org
2021-11-05 13:42 ` rguenth at gcc dot gnu.org
2022-03-18 12:16 ` ppalka 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).