public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95686] New: undefined reference to static local variable within inline function
@ 2020-06-15 17:51 leni536 at gmail dot com
2020-06-16 6:40 ` [Bug c++/95686] " rguenth at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: leni536 at gmail dot com @ 2020-06-15 17:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Bug ID: 95686
Summary: undefined reference to static local variable within
inline function
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: leni536 at gmail dot com
Target Milestone: ---
The following code produces an "undefined reference to `foo()::i'" linker
error:
template <const int* ptr>
struct S {
static constexpr const int* value = ptr;
};
inline
auto foo() {
static const int i = 0;
return S<&i>{};
}
#include <iostream>
int main() {
std::cout << decltype(foo())::value;
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
@ 2020-06-16 6:40 ` rguenth at gcc dot gnu.org
2020-06-16 7:14 ` leni536 at gmail dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-16 6:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|11.0 |9.3.0
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Known to fail| |9.3.0
Last reconfirmed| |2020-06-16
Keywords| |accepts-invalid
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
clang complains
t.C:9:16: error: non-type template argument refers to object 'i' that does not
have linkage
return S<&i>{};
^
t.C:8:26: note: non-type template argument refers to object here
static const int i = 0;
^
so this means your code is ill-formed. I can confirm your observation
with GCC 9.3 but GCC 10.1 rejects the code as well:
t.C: In function ?auto foo()?:
t.C:9:17: error: ?& i? is not a valid template argument of type ?const int*?
because ?i? has no linkage
9 | return S<&i>{};
| ^
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
2020-06-16 6:40 ` [Bug c++/95686] " rguenth at gcc dot gnu.org
@ 2020-06-16 7:14 ` leni536 at gmail dot com
2020-06-16 17:37 ` daniel.kruegler at googlemail dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: leni536 at gmail dot com @ 2020-06-16 7:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
--- Comment #2 from Lénárd Szolnoki <leni536 at gmail dot com> ---
I failed to mention that I compiled the example in -std=c++17. With this
compiler option it compiles but fails to link in gcc. It compiles, links and
runs as expected in clang.
The linkage requirement for reference/pointer non-type template arguments were
lifted in C++17.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
2020-06-16 6:40 ` [Bug c++/95686] " rguenth at gcc dot gnu.org
2020-06-16 7:14 ` leni536 at gmail dot com
@ 2020-06-16 17:37 ` daniel.kruegler at googlemail dot com
2021-08-13 8:25 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2020-06-16 17:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler@googlemail.
| |com
--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Lénárd Szolnoki from comment #2)
> I failed to mention that I compiled the example in -std=c++17. With this
> compiler option it compiles but fails to link in gcc. It compiles, links and
> runs as expected in clang.
>
> The linkage requirement for reference/pointer non-type template arguments
> were lifted in C++17.
According to https://gcc.gnu.org/bugs/ the compile options have to be provided
for every bug report. Here is a slightly simplified reproducer free of any
library dependencies:
Compiler options:
-Wall -Wextra -std=c++2a -pedantic
//---------------
template <const int* ptr>
struct S {
static constexpr const int* value = ptr;
};
inline
auto foo() {
static const int i = 0;
return S<&i>{};
}
void bar(const int*){}
int main() {
bar(decltype(foo())::value);
}
//---------------
Diagnostic output:
//----------------
/tmp/cci6dPre.o: In function `main':
prog.cc:(.text+0x10): undefined reference to `foo()::i'
collect2: error: ld returned 1 exit status
//----------------
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (2 preceding siblings ...)
2020-06-16 17:37 ` daniel.kruegler at googlemail dot com
@ 2021-08-13 8:25 ` pinskia at gcc dot gnu.org
2021-10-13 3:30 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-13 8:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=53164
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect the same issue as in PR 53164 is the problem here.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (3 preceding siblings ...)
2021-08-13 8:25 ` pinskia at gcc dot gnu.org
@ 2021-10-13 3:30 ` pinskia at gcc dot gnu.org
2021-10-13 3:32 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-13 3:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |asolokha at gmx dot com
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102723 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (4 preceding siblings ...)
2021-10-13 3:30 ` pinskia at gcc dot gnu.org
@ 2021-10-13 3:32 ` pinskia at gcc dot gnu.org
2023-03-19 19:05 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-13 3:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-valid-code, lto
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note this code ICEs with LTO turned on also.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (5 preceding siblings ...)
2021-10-13 3:32 ` pinskia at gcc dot gnu.org
@ 2023-03-19 19:05 ` pinskia at gcc dot gnu.org
2023-03-19 19:06 ` pinskia at gcc dot gnu.org
2023-03-19 19:07 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-19 19:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 109185 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (6 preceding siblings ...)
2023-03-19 19:05 ` pinskia at gcc dot gnu.org
@ 2023-03-19 19:06 ` pinskia at gcc dot gnu.org
2023-03-19 19:07 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-19 19:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the testcase is very similar to clang's
test/SemaTemplate/instantiate-static-local.cpp testcase.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/95686] undefined reference to static local variable within inline function
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
` (7 preceding siblings ...)
2023-03-19 19:06 ` pinskia at gcc dot gnu.org
@ 2023-03-19 19:07 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-19 19:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95686
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #6)
> Note this code ICEs with LTO turned on also.
The ICE is:
during IPA pass: modref
rls6o5bx.cpp:10:1: internal compiler error: in get_partitioning_class, at
symtab.cc:2096
10 | }
| ^
0x7a6b1d symtab_node::get_partitioning_class()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/symtab.cc:2096
0x105d777 lto_output_varpool_node
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/lto-cgraph.cc:631
0x105d777 output_symtab()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/lto-cgraph.cc:999
0x1074fdc lto_output()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/lto-streamer-out.cc:2825
0x1103181 write_lto
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/passes.cc:2784
0x1103181 ipa_write_summaries_1
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/passes.cc:2848
0x1103181 ipa_write_summaries()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/passes.cc:2904
0xd3dd92 ipa_passes
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/cgraphunit.cc:2250
0xd3dd92 symbol_table::compile()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/cgraphunit.cc:2323
0xd405e7 symbol_table::compile()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/cgraphunit.cc:2303
0xd405e7 symbol_table::finalize_compilation_unit()
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230312/work/gcc-13-20230312/gcc/cgraphunit.cc:2575
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-03-19 19:07 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 17:51 [Bug c++/95686] New: undefined reference to static local variable within inline function leni536 at gmail dot com
2020-06-16 6:40 ` [Bug c++/95686] " rguenth at gcc dot gnu.org
2020-06-16 7:14 ` leni536 at gmail dot com
2020-06-16 17:37 ` daniel.kruegler at googlemail dot com
2021-08-13 8:25 ` pinskia at gcc dot gnu.org
2021-10-13 3:30 ` pinskia at gcc dot gnu.org
2021-10-13 3:32 ` pinskia at gcc dot gnu.org
2023-03-19 19:05 ` pinskia at gcc dot gnu.org
2023-03-19 19:06 ` pinskia at gcc dot gnu.org
2023-03-19 19:07 ` 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).