This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81716] New: Bogus -Wlto warning with forward-declared pointers
- From: "sgunderson at bigfoot dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 04 Aug 2017 11:08:50 +0000
- Subject: [Bug c++/81716] New: Bogus -Wlto warning with forward-declared pointers
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81716
Bug ID: 81716
Summary: Bogus -Wlto warning with forward-declared pointers
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sgunderson at bigfoot dot com
Target Milestone: ---
Hi,
It seems that if you forward-declare a class in one translation unit (and use
pointers to it), it will count as a different type for LTO detection purposes,
which doesn't sound right. Might there be that it implicitly gets a type of
nullptr_t? Or something else?
gcc version 8.0.0 20170618 (experimental) [trunk revision 249349] (Debian
20170618-1)
atum17:~> cat test1.cc
class S;
extern S *q[10];
void foo(S *t)
{
q[0] = nullptr;
}
atum17:~> cat test2.cc
#include <stdio.h>
class S {
int m;
};
extern S *q[10];
void bar(S *t)
{
printf("%p\n", q[0]);
}
atum17:~> /usr/lib/gcc-snapshot/bin/g++ -Wall -O2 -flto -o test.so test1.cc
test2.cc
test2.cc:6:11: warning: type of 'q' does not match original declaration
[-Wlto-type-mismatch]
extern S *q[10];
^
test1.cc:2:11: note: 'q' was previously declared here
extern S *q[10];
^
test1.cc:2:11: note: code may be misoptimized unless -fno-strict-aliasing is
used
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status