From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7948) id 2C05B38582A8; Fri, 26 Jan 2024 11:29:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C05B38582A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706268549; bh=X7IEnPS4mkmglzoH0EjJKBRWrnZuKaPahi9F5LYqYnE=; h=From:To:Subject:Date:From; b=Ks3NizySmcV08d+YpX1cLZRwhbA+wlyEcMF1BKVCKerRcPxhsBWfOrMv2J46Ve4sU CoQJPDGp42cTS9NnvYou2/ugHIIU+8hXnWyHwwK0N+NUUgdT+XXLj4qo9fC86OdUT7 5uR6tToi+4yEWIg1HKNKzfWj2QkTw/lxL0oJJj9A= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Nathaniel Shead To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8451] c++: Emit definitions of ODR-used static members imported from modules [PR112899] X-Act-Checkin: gcc X-Git-Author: Nathaniel Shead X-Git-Refname: refs/heads/master X-Git-Oldrev: f9b143d239db775318a29e9ff63f232b9501a22a X-Git-Newrev: a0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a Message-Id: <20240126112909.2C05B38582A8@sourceware.org> Date: Fri, 26 Jan 2024 11:29:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a commit r14-8451-ga0dde47f84f17cbe7fa2fb41c14c5a2db8c4d63a Author: Nathaniel Shead Date: Wed Jan 3 09:27:06 2024 +1100 c++: Emit definitions of ODR-used static members imported from modules [PR112899] Static data members marked 'inline' should be emitted in TUs where they are ODR-used. We need to make sure that inlines imported from modules are correctly added to the 'pending_statics' map so that they get emitted if needed, otherwise the attached testcase fails to link. PR c++/112899 gcc/cp/ChangeLog: * cp-tree.h (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * decl2.cc (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * pt.cc (instantiate_decl): Rename usage of above function. * module.cc (trees_in::read_var_def): Remember pending statics that we stream in. gcc/testsuite/ChangeLog: * g++.dg/modules/init-4_a.C: New test. * g++.dg/modules/init-4_b.C: New test. * g++.dg/modules/init-6_a.H: New test. * g++.dg/modules/init-6_b.C: New test. Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka Reviewed-by: Jason Merrill +struct __from_chars_alnum_to_val_table { + static inline int value = 42; +}; + +inline unsigned char +__from_chars_alnum_to_val() { + return __from_chars_alnum_to_val_table::value; +} + +template +static inline int nonclass_value = 42; + +inline unsigned char +get_nonclass_val() { + return nonclass_value; +} diff --git a/gcc/testsuite/g++.dg/modules/init-6_b.C b/gcc/testsuite/g++.dg/modules/init-6_b.C new file mode 100644 index 000000000000..d704968ec375 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-6_b.C @@ -0,0 +1,9 @@ +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "init-6_a.H"; + +int main() { + __from_chars_alnum_to_val(); + get_nonclass_val(); +}