public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114170] New: [modules] error streaming in header unit with instantiated variable template with non-trivial initializer
@ 2024-02-29 15:48 ppalka at gcc dot gnu.org
2024-03-01 22:05 ` [Bug c++/114170] " cvs-commit at gcc dot gnu.org
2024-03-01 22:08 ` nshead at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-02-29 15:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114170
Bug ID: 114170
Summary: [modules] error streaming in header unit with
instantiated variable template with non-trivial
initializer
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppalka at gcc dot gnu.org
Target Milestone: ---
$ cat testcase.H
inline int f() { return 42; }
template<class>
inline int v = f();
inline int g() { return v<int>; }
$ cat testcase.C
import "testcase.H";
int main() {
return v<int> != 42;
}
$ g++ -fmodules-ts testcase.{H,C}
In module imported at testcase.C:1:1:
testcase.H: error: failed to read compiled module: Bad file data
testcase.H: note: compiled module file is ‘gcm.cache/,/testcase.H.gcm’
testcase.H: fatal error: returning to the gate for a mechanical issue
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/114170] [modules] error streaming in header unit with instantiated variable template with non-trivial initializer
2024-02-29 15:48 [Bug c++/114170] New: [modules] error streaming in header unit with instantiated variable template with non-trivial initializer ppalka at gcc dot gnu.org
@ 2024-03-01 22:05 ` cvs-commit at gcc dot gnu.org
2024-03-01 22:08 ` nshead at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-01 22:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114170
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:
https://gcc.gnu.org/g:852b58552991099141f9df5782e1f28d8606af9d
commit r14-9267-g852b58552991099141f9df5782e1f28d8606af9d
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date: Fri Mar 1 11:08:23 2024 +1100
c++: Stream definitions for implicit instantiations [PR114170]
An implicit instantiation has an initializer depending on whether
DECL_INITIALIZED_P is set (like normal VAR_DECLs) which needs to be
written to ensure that consumers of header modules properly emit
definitions for these instantiations. This patch ensures that we
correctly fallback to checking this flag when DECL_INITIAL is not set
for a template instantiation.
For variables with non-trivial dynamic initialization, DECL_INITIAL can
be empty after 'split_nonconstant_init' but DECL_INITIALIZED_P is still
set; we need to check the latter to determine if we need to go looking
for a definition to emit (often in 'static_aggregates' here). This is
the case in the linked testcase.
However, for template specialisations (not instantiations?) we primarily
care about DECL_INITIAL; if the variable has initialization depending on
a template parameter then we'll need to emit that definition even though
it doesn't yet have DECL_INITIALIZED_P set; this is the case in e.g.
template <int N> int value = N;
As a drive-by fix, also ensures that the count of initializers matches
the actual number of initializers written. This doesn't seem to be
necessary for correctness in the current testsuite, but feels wrong and
makes debugging harder when initializers aren't properly written for
other reasons.
PR c++/114170
gcc/cp/ChangeLog:
* module.cc (has_definition): Fall back to DECL_INITIALIZED_P
when DECL_INITIAL is not set on a template.
(module_state::write_inits): Only increment count when
initializers are actually written.
gcc/testsuite/ChangeLog:
* g++.dg/modules/var-tpl-2_a.H: New test.
* g++.dg/modules/var-tpl-2_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/114170] [modules] error streaming in header unit with instantiated variable template with non-trivial initializer
2024-02-29 15:48 [Bug c++/114170] New: [modules] error streaming in header unit with instantiated variable template with non-trivial initializer ppalka at gcc dot gnu.org
2024-03-01 22:05 ` [Bug c++/114170] " cvs-commit at gcc dot gnu.org
@ 2024-03-01 22:08 ` nshead at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-03-01 22:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114170
Nathaniel Shead <nshead at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nshead at gcc dot gnu.org
Resolution|--- |FIXED
Assignee|unassigned at gcc dot gnu.org |nshead at gcc dot gnu.org
Target Milestone|--- |14.0
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-01 22:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 15:48 [Bug c++/114170] New: [modules] error streaming in header unit with instantiated variable template with non-trivial initializer ppalka at gcc dot gnu.org
2024-03-01 22:05 ` [Bug c++/114170] " cvs-commit at gcc dot gnu.org
2024-03-01 22:08 ` nshead 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).