public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14
@ 2021-11-05 8:37 fchelnokov at gmail dot com
2021-11-05 9:20 ` [Bug c++/103092] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: fchelnokov at gmail dot com @ 2021-11-05 8:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
Bug ID: 103092
Summary: Non-throwing function pointer can point to a
throwing-function in C++14
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
```
void func(){}
int main() {
void(*pFn)() noexcept(true);
pFn = func;
(void)pFn;
}
```
is accepted by GCC in C++14 mode (but not by Clang), demo:
https://gcc.godbolt.org/z/a3EjxcKvz
Starting from C++17, GCC also rejects it. Could you please verify C++14 mode
here?
Related discussion: https://stackoverflow.com/q/66574353/7325599
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103092] Non-throwing function pointer can point to a throwing-function in C++14
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
@ 2021-11-05 9:20 ` redi at gcc dot gnu.org
2021-11-05 9:26 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-05 9:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-11-05
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The relevant rule before C++17 is [except.spec] p5
"A similar restriction applies to assignment to and initialization of pointers
to
functions, pointers to member functions, and references to functions: the
target entity shall allow at least the exceptions allowed by the source value
in the assignment or initialization."
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103092] Non-throwing function pointer can point to a throwing-function in C++14
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
2021-11-05 9:20 ` [Bug c++/103092] " redi at gcc dot gnu.org
@ 2021-11-05 9:26 ` redi at gcc dot gnu.org
2021-11-05 22:45 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-05 9:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
G++ does not give an error for the example in p5:
class A { /* ... */ };
void (*pf1)(); // no exception specification
void (*pf2)() throw(A);
void f() {
pf1 = pf2; // OK: pf1 is less restrictive
pf2 = pf1; // error: pf2 is more restrictive
}
That should be ill-formed in C++98/11/14.
The equivalent with a noexcept-specifier would be:
class A { /* ... */ };
void (*pf1)(); // no exception specification
void (*pf2)() noexcept;
void f() {
pf1 = pf2; // OK: pf1 is less restrictive
pf2 = pf1; // error: pf2 is more restrictive
}
G++ doesn't reject this in 98/11/14, only C++17 and up.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103092] Non-throwing function pointer can point to a throwing-function in C++14
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
2021-11-05 9:20 ` [Bug c++/103092] " redi at gcc dot gnu.org
2021-11-05 9:26 ` redi at gcc dot gnu.org
@ 2021-11-05 22:45 ` pinskia at gcc dot gnu.org
2021-11-06 0:28 ` redi at gcc dot gnu.org
2021-11-06 4:55 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-05 22:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Blocks| |12255
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> G++ does not give an error for the example in p5:
>
> class A { /* ... */ };
> void (*pf1)(); // no exception specification
> void (*pf2)() throw(A);
>
> void f() {
> pf1 = pf2; // OK: pf1 is less restrictive
> pf2 = pf1; // error: pf2 is more restrictive
> }
>
> That should be ill-formed in C++98/11/14.
The above testcase is PR 12255.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12255
[Bug 12255] [C++98/11/14 only] exception-specification ignored on pointer to
function
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103092] Non-throwing function pointer can point to a throwing-function in C++14
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
` (2 preceding siblings ...)
2021-11-05 22:45 ` pinskia at gcc dot gnu.org
@ 2021-11-06 0:28 ` redi at gcc dot gnu.org
2021-11-06 4:55 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-06 0:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah yes, and I think this is a dup of pr 49332
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/103092] Non-throwing function pointer can point to a throwing-function in C++14
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
` (3 preceding siblings ...)
2021-11-06 0:28 ` redi at gcc dot gnu.org
@ 2021-11-06 4:55 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-06 4:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103092
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 49332.
*** This bug has been marked as a duplicate of bug 49332 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-06 4:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 8:37 [Bug c++/103092] New: Non-throwing function pointer can point to a throwing-function in C++14 fchelnokov at gmail dot com
2021-11-05 9:20 ` [Bug c++/103092] " redi at gcc dot gnu.org
2021-11-05 9:26 ` redi at gcc dot gnu.org
2021-11-05 22:45 ` pinskia at gcc dot gnu.org
2021-11-06 0:28 ` redi at gcc dot gnu.org
2021-11-06 4:55 ` 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).