public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable
@ 2020-05-27 15:24 rafael at espindo dot la
  2020-05-27 16:35 ` [Bug c++/95368] " daniel.kruegler at googlemail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rafael at espindo dot la @ 2020-05-27 15:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95368
           Summary: gcc things that a lambda capture is both const and
                    mutable
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rafael at espindo dot la
  Target Milestone: ---

gcc accepts

#include <utility>

struct foo {
    void func();
};

void bar(foo& v) {
    [v]() {
        static_assert(std::is_same_v<decltype(v), foo&>);
        [v]() mutable {
            static_assert(std::is_same_v<decltype(v), foo&>);
//            v.func();                                                         
        }();
    }();
}


But uncomment the call and you get

test.cc:12:20: error: passing ‘const foo’ as ‘this’ argument discards
qualifiers [-fpermissive]
   12 |             v.func();

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

* [Bug c++/95368] gcc things that a lambda capture is both const and mutable
  2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
@ 2020-05-27 16:35 ` daniel.kruegler at googlemail dot com
  2020-05-28 17:00 ` rafael at espindo dot la
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2020-05-27 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Rafael Avila de Espindola from comment #0)
> gcc accepts
> 
[..]

I found your code confusing, because the actual problem becomes visible only
under certain conditions. So lets make it a proper example, that shows the
problem immediately and lets ensure that we make it free from library
dependencies and provide all required information:

When using 

gcc HEAD 11.0.0 20200525 (experimental) 

and the following compiler flags

-Wall -Wextra -std=gnu++2a -pedantic 

to compile this code:

//---------
template<class, class>
constexpr bool is_same_v = false;

template<class T>
constexpr bool is_same_v<T, T> = true;

struct foo
{
  void func() {}
};

void bar(foo& v) {
  [v]() {
    static_assert(is_same_v<decltype(v), foo&>);
    [v]() mutable {
      static_assert(is_same_v<decltype(v), foo&>);
      v.func();
    }();
  }();
}

int main() {}
//---------

the program is rejected (but should be accepted) with the following
diagnostics:

```
prog.cc: In lambda function:
prog.cc:17:16: error: passing 'const foo' as 'this' argument discards
qualifiers [-fpermissive]
   17 |         v.func();
      |                ^
prog.cc:9:8: note:   in call to 'void foo::func()'
    9 |   void func() {}
      |        ^~~~
```

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

* [Bug c++/95368] gcc things that a lambda capture is both const and mutable
  2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
  2020-05-27 16:35 ` [Bug c++/95368] " daniel.kruegler at googlemail dot com
@ 2020-05-28 17:00 ` rafael at espindo dot la
  2021-12-28  9:55 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rafael at espindo dot la @ 2020-05-28 17:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Rafael Avila de Espindola <rafael at espindo dot la> ---
I just tested a few compilers with the testcase from comment 1:

* clang version 11.0.0 (https://github.com/llvm/llvm-project.git
0796b170fb3bf38e6cc4e59746120b37c9a9cd9f):
  Accepts it.

* g++ (GCC) 10.1.1 20200507 (Red Hat 10.1.1-1):
  Rejects it:
  test.cc:17:14: error: passing ‘const foo’ as ‘this’ argument discards
qualifiers [-fpermissive]

* gcc (GCC) 9.3.1 20200528
  Rejects it:
  test.cc:17:14: error: passing ‘const foo’ as ‘this’ argument discards
qualifiers

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

* [Bug c++/95368] gcc things that a lambda capture is both const and mutable
  2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
  2020-05-27 16:35 ` [Bug c++/95368] " daniel.kruegler at googlemail dot com
  2020-05-28 17:00 ` rafael at espindo dot la
@ 2021-12-28  9:55 ` pinskia at gcc dot gnu.org
  2021-12-28  9:56 ` pinskia at gcc dot gnu.org
  2021-12-28 10:01 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-28  9:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.1.0
      Known to work|                            |12.0
           Keywords|                            |needs-bisection

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks to be fixed on the trunk.

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

* [Bug c++/95368] gcc things that a lambda capture is both const and mutable
  2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
                   ` (2 preceding siblings ...)
  2021-12-28  9:55 ` pinskia at gcc dot gnu.org
@ 2021-12-28  9:56 ` pinskia at gcc dot gnu.org
  2021-12-28 10:01 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-28  9:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-28
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

* [Bug c++/95368] gcc things that a lambda capture is both const and mutable
  2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
                   ` (3 preceding siblings ...)
  2021-12-28  9:56 ` pinskia at gcc dot gnu.org
@ 2021-12-28 10:01 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-28 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 94376

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

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

end of thread, other threads:[~2021-12-28 10:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 15:24 [Bug c++/95368] New: gcc things that a lambda capture is both const and mutable rafael at espindo dot la
2020-05-27 16:35 ` [Bug c++/95368] " daniel.kruegler at googlemail dot com
2020-05-28 17:00 ` rafael at espindo dot la
2021-12-28  9:55 ` pinskia at gcc dot gnu.org
2021-12-28  9:56 ` pinskia at gcc dot gnu.org
2021-12-28 10:01 ` pinskia 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).