public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor
@ 2022-02-23 12:40 fchelnokov at gmail dot com
  2022-02-23 23:14 ` [Bug c++/104661] [C++17+] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fchelnokov at gmail dot com @ 2022-02-23 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104661
           Summary: Catching exception by const value when
                    exception-object has lvalue-reference constructor
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program
```
struct A {
    A() {}
    A(A&) {}
};

int main() {
    try {
        throw A{};
    }
    catch ( const A ) {
    }
}
```
is presumably valid and accepted by Clang and MSVC, but GCC complains:
```
error: binding reference of type 'A&' to 'const A' discards qualifiers
   10 |     catch ( const A ) {
      |                   ^
<source>:3:7: note:   initializing argument 1 of 'A::A(A&)'
    3 |     A(A&) {}
      |       ^~
```
Demo: https://gcc.godbolt.org/z/as671TGqs

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

* [Bug c++/104661] [C++17+] Catching exception by const value when exception-object has lvalue-reference constructor
  2022-02-23 12:40 [Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor fchelnokov at gmail dot com
@ 2022-02-23 23:14 ` pinskia at gcc dot gnu.org
  2022-02-23 23:21 ` pinskia at gcc dot gnu.org
  2023-09-01 14:10 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-23 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Catching exception by const |[C++17+] Catching exception
                   |value when exception-object |by const value when
                   |has lvalue-reference        |exception-object has
                   |constructor                 |lvalue-reference
                   |                            |constructor

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note clang accepts the code only with -std=c++17 and -std=c++20 as you didn't
mention in the bug report as you passing. C++17 changed some rules and all.

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

* [Bug c++/104661] [C++17+] Catching exception by const value when exception-object has lvalue-reference constructor
  2022-02-23 12:40 [Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor fchelnokov at gmail dot com
  2022-02-23 23:14 ` [Bug c++/104661] [C++17+] " pinskia at gcc dot gnu.org
@ 2022-02-23 23:21 ` pinskia at gcc dot gnu.org
  2023-09-01 14:10 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-23 23:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=103048
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-02-23

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, related to PR 103048.

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

* [Bug c++/104661] [C++17+] Catching exception by const value when exception-object has lvalue-reference constructor
  2022-02-23 12:40 [Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor fchelnokov at gmail dot com
  2022-02-23 23:14 ` [Bug c++/104661] [C++17+] " pinskia at gcc dot gnu.org
  2022-02-23 23:21 ` pinskia at gcc dot gnu.org
@ 2023-09-01 14:10 ` fchelnokov at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fchelnokov at gmail dot com @ 2023-09-01 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Related discussion: https://stackoverflow.com/a/77021213/7325599

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

end of thread, other threads:[~2023-09-01 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 12:40 [Bug c++/104661] New: Catching exception by const value when exception-object has lvalue-reference constructor fchelnokov at gmail dot com
2022-02-23 23:14 ` [Bug c++/104661] [C++17+] " pinskia at gcc dot gnu.org
2022-02-23 23:21 ` pinskia at gcc dot gnu.org
2023-09-01 14:10 ` fchelnokov at gmail dot com

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).