public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105848] New: undefined reference for default template argument of function type
@ 2022-06-04 20:21 dk.1995-fast at yandex dot ru
2022-06-04 23:01 ` [Bug c++/105848] [12 Regression] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: dk.1995-fast at yandex dot ru @ 2022-06-04 20:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
Bug ID: 105848
Summary: undefined reference for default template argument of
function type
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dk.1995-fast at yandex dot ru
Target Milestone: ---
Following code produces link-time error in new version of GCC.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-bootstrap
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-linker-build-id --enable-lto
--enable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (GCC)
$ cat main.cpp
template<typename T>
void def()
{}
template<void (*foobar)() = def<int>>
void bar()
{
foobar();
}
template<typename T>
void foo()
{
bar();
}
int main()
{
foo<int>();
}
$ gcc main.cpp
/usr/bin/ld: /tmp/ccbVvQNJ.o: in function `void bar<&(void def<int>())>()':
main.cpp:(.text._Z3barIXadL_Z3defIiEvvEEEvv[_Z3barIXadL_Z3defIiEvvEEEvv]+0x5):
undefined reference to `void def<int>()'
collect2: error: ld returned 1 exit status
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
@ 2022-06-04 23:01 ` pinskia at gcc dot gnu.org
2022-06-06 12:30 ` [Bug c++/105848] [12/13 " ppalka at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-04 23:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-06-04
Ever confirmed|0 |1
Keywords| |needs-bisection
Summary|undefined reference for |[12 Regression] undefined
|default template argument |reference for default
|of function type |template argument of
| |function type
Target Milestone|--- |12.2
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12/13 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
2022-06-04 23:01 ` [Bug c++/105848] [12 Regression] " pinskia at gcc dot gnu.org
@ 2022-06-06 12:30 ` ppalka at gcc dot gnu.org
2022-06-06 18:29 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-06-06 12:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Known to fail| |13.0
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Summary|[12 Regression] undefined |[12/13 Regression]
|reference for default |undefined reference for
|template argument of |default template argument
|function type |of function type
Status|NEW |ASSIGNED
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r12-6075-g2decd2cabe5a4f.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12/13 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
2022-06-04 23:01 ` [Bug c++/105848] [12 Regression] " pinskia at gcc dot gnu.org
2022-06-06 12:30 ` [Bug c++/105848] [12/13 " ppalka at gcc dot gnu.org
@ 2022-06-06 18:29 ` cvs-commit at gcc dot gnu.org
2022-07-21 16:48 ` [Bug c++/105848] [12 " cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-06 18:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:733a792a2b2e1662e738fa358b45a2720a8618a7
commit r13-995-g733a792a2b2e1662e738fa358b45a2720a8618a7
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Jun 6 14:29:12 2022 -0400
c++: function NTTP argument considered unused [PR53164, PR105848]
Here at parse time the template argument f (an OVERLOAD) in A<f> gets
resolved ahead of time to the FUNCTION_DECL f<int>, and we defer marking
f<int> as used until instantiation (of g) as usual.
Later when instantiating g the type A<f> (where f has already been
resolved) is non-dependent, so tsubst_aggr_type avoids re-processing its
template arguments, and we end up never actually marking f<int> as used
(which means we never instantiate it) even though A<f>::h() later calls
it, leading to a link error.
This patch works around this issue by looking through ADDR_EXPR when
calling mark_used on the substituted callee of a CALL_EXPR.
PR c++/53164
PR c++/105848
gcc/cp/ChangeLog:
* pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Look through an
ADDR_EXPR callee when calling mark_used.
gcc/testsuite/ChangeLog:
* g++.dg/template/fn-ptr3.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
` (2 preceding siblings ...)
2022-06-06 18:29 ` cvs-commit at gcc dot gnu.org
@ 2022-07-21 16:48 ` cvs-commit at gcc dot gnu.org
2022-07-21 16:51 ` ppalka at gcc dot gnu.org
2023-04-01 14:19 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-21 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:670ef5b108d0acfbde96f44b064079f2fa0c92d4
commit r12-8604-g670ef5b108d0acfbde96f44b064079f2fa0c92d4
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Jun 6 14:29:12 2022 -0400
c++: function NTTP argument considered unused [PR53164, PR105848]
Here at parse time the template argument f (an OVERLOAD) in A<f> gets
resolved ahead of time to the FUNCTION_DECL f<int>, and we defer marking
f<int> as used until instantiation (of g) as usual.
Later when instantiating g the type A<f> (where f has already been
resolved) is non-dependent, so tsubst_aggr_type avoids re-processing its
template arguments, and we end up never actually marking f<int> as used
(which means we never instantiate it) even though A<f>::h() later calls
it, leading to a link error.
This patch works around this issue by looking through ADDR_EXPR when
calling mark_used on the substituted callee of a CALL_EXPR.
PR c++/53164
PR c++/105848
gcc/cp/ChangeLog:
* pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Look through an
ADDR_EXPR callee when calling mark_used.
gcc/testsuite/ChangeLog:
* g++.dg/template/fn-ptr3.C: New test.
(cherry picked from commit 733a792a2b2e1662e738fa358b45a2720a8618a7)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
` (3 preceding siblings ...)
2022-07-21 16:48 ` [Bug c++/105848] [12 " cvs-commit at gcc dot gnu.org
@ 2022-07-21 16:51 ` ppalka at gcc dot gnu.org
2023-04-01 14:19 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-07-21 16:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.2/13
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105848] [12 Regression] undefined reference for default template argument of function type
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
` (4 preceding siblings ...)
2022-07-21 16:51 ` ppalka at gcc dot gnu.org
@ 2023-04-01 14:19 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-01 14:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:b5e38b1c166357e2a63d38ae6da7ae5d68fc115b
commit r13-6970-gb5e38b1c166357e2a63d38ae6da7ae5d68fc115b
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Apr 1 10:19:08 2023 -0400
c++: improve "NTTP argument considered unused" fix [PR53164, PR105848]
r13-995-g733a792a2b2e16 worked around the problem of (pointer to)
function NTTP arguments not always getting marked as odr-used, by
redundantly calling mark_used on the substituted ADDR_EXPR callee of a
CALL_EXPR. That is just a narrow workaround however, since it assumes
the function is later called, but the use as a template argument alone
should constitute an odr-use of the function (since template arguments
are an evaluated context, and we're really passing its address); we
shouldn't need to subsequently call or otherwise use the function NTTP
argument.
This patch fixes this in a more general way by walking the template
arguments of each specialization that's about to be instantiated and
redundantly calling mark_used on all entities used within. As before,
the call to mark_used as it worst a no-op, but it compensates for the
situation where the specialization was first formed in a template context
in which mark_used is inhibited.
Another approach would be to call mark_used whenever we substitute a
TEMPLATE_PARM_INDEX, but that would result in many more redundant calls
to mark_used compared to this approach. And as the second testcase
below illustrates, we also need to walk C++20 class NTTP arguments which
can be large and thus expensive to walk repeatedly. The change to
invalid_tparm_referent_p is needed to avoid incorrectly rejecting class
NTTP arguments containing function pointers as in the testcase.
(The third testcase is unrelated to this fix, but it helped rule out an
earlier approach I was considering and it seems we don't have existing
test coverage for this situation.)
PR c++/53164
PR c++/105848
gcc/cp/ChangeLog:
* pt.cc (invalid_tparm_referent_p): Accept ADDR_EXPR of
FUNCTION_DECL.
(instantiate_class_template): Call mark_template_arguments_used.
(tsubst_copy_and_build) <case CALL_EXPR>: Revert r13-995 change.
(mark_template_arguments_used): Define.
(instantiate_body): Call mark_template_arguments_used.
gcc/testsuite/ChangeLog:
* g++.dg/template/fn-ptr3a.C: New test.
* g++.dg/template/fn-ptr3b.C: New test.
* g++.dg/template/fn-ptr4.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-01 14:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-04 20:21 [Bug c++/105848] New: undefined reference for default template argument of function type dk.1995-fast at yandex dot ru
2022-06-04 23:01 ` [Bug c++/105848] [12 Regression] " pinskia at gcc dot gnu.org
2022-06-06 12:30 ` [Bug c++/105848] [12/13 " ppalka at gcc dot gnu.org
2022-06-06 18:29 ` cvs-commit at gcc dot gnu.org
2022-07-21 16:48 ` [Bug c++/105848] [12 " cvs-commit at gcc dot gnu.org
2022-07-21 16:51 ` ppalka at gcc dot gnu.org
2023-04-01 14:19 ` cvs-commit 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).