public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111750] New: Spurious -Warray-bounds warning when using member function pointers
@ 2023-10-09 23:53 abbeyj+gcc at gmail dot com
2023-10-10 1:35 ` [Bug tree-optimization/111750] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: abbeyj+gcc at gmail dot com @ 2023-10-09 23:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111750
Bug ID: 111750
Summary: Spurious -Warray-bounds warning when using member
function pointers
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: abbeyj+gcc at gmail dot com
Target Milestone: ---
Created attachment 56086
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56086&action=edit
Reproducer
The source code below generates a -Warray-bounds warning which I believe is
incorrect. Compile with `g++ -c -Wall -O2`.
```
struct MyClass {
void my_method();
};
MyClass g;
void pre();
inline void FetchValue(MyClass& c, void(MyClass::*func)()) {
pre();
(c.*func)();
}
int get_int();
inline int Check() {
static const int ret = get_int();
return ret;
}
inline void ReadValue(MyClass& c, void(MyClass::*func)()) {
Check();
FetchValue(c, func);
}
void Main() {
ReadValue(g, &MyClass::my_method);
}
```
This produces:
```
In function 'void FetchValue(MyClass&, void (MyClass::*)())',
inlined from 'void ReadValue(MyClass&, void (MyClass::*)())' at
<source>:23:15,
inlined from 'void Main()' at <source>:27:14:
<source>:11:14: warning: array subscript 'int (**)(...)[0]' is partly outside
array bounds of 'MyClass [1]' [-Warray-bounds=]
11 | (c.*func)();
| ~~~~~~~~~^~
<source>: In function 'void Main()':
<source>:5:9: note: object 'g' of size 1
5 | MyClass g;
| ^
```
Godbolt link: https://godbolt.org/z/6YsWd9xhr
That this source produces a -Warray-bounds warning is somewhat surprising since
it contains no arrays, no array indexing, and no pointer arithmetic. Small
changes such as removing the static variable or manually inlining a function
into its caller make the warning go away.
The earliest version that I've been able to reproduce this with is GCC 11.1 and
it still reproduces on the trunk version that's currently available on
godbolt.org.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-10 1:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 23:53 [Bug tree-optimization/111750] New: Spurious -Warray-bounds warning when using member function pointers abbeyj+gcc at gmail dot com
2023-10-10 1:35 ` [Bug tree-optimization/111750] " 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).