Hi! The following testcase ICEs with -fno-weak, because maybe_commonize_var clears TREE_PUBLIC/DECL_COMMON, but later we assume that if !DECL_INTERFACE_KNOWN that TREE_PUBLIC is true. Other spots that clear TREE_PUBLIC also set DECL_INTERFACE_KNOWN, e.g. twice in optimize.c: cp/optimize.c- TREE_PUBLIC (fn) = false; cp/optimize.c- DECL_EXTERNAL (fn) = false; cp/optimize.c: DECL_INTERFACE_KNOWN (fn) = true;
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-02-20 Jakub Jelinek <ja...@redhat.com> PR c++/89405 * decl.c (maybe_commonize_var): When clearing TREE_PUBLIC and DECL_COMMON, set DECL_INTERFACE_KNOWN. * g++.dg/cpp1z/inline-var5.C: New test. --- gcc/cp/decl.c.jj 2019-02-14 08:06:37.905546103 +0100 +++ gcc/cp/decl.c 2019-02-20 13:31:07.721873449 +0100 @@ -5634,6 +5634,7 @@ maybe_commonize_var (tree decl) be merged. */ TREE_PUBLIC (decl) = 0; DECL_COMMON (decl) = 0; + DECL_INTERFACE_KNOWN (decl) = 1; const char *msg; if (DECL_INLINE_VAR_P (decl)) msg = G_("sorry: semantics of inline variable " --- gcc/testsuite/g++.dg/cpp1z/inline-var5.C.jj 2019-02-20 14:25:41.799665033 +0100 +++ gcc/testsuite/g++.dg/cpp1z/inline-var5.C 2019-02-20 14:25:09.813194982 +0100 @@ -0,0 +1,11 @@ +// PR c++/89405 +// { dg-do compile { target c++17 } } +// { dg-options "-fno-weak" } + +template <int N> +struct S +{ + static constexpr int a = N; // { dg-warning "semantics of inline variable" } +}; // { dg-message "you can work around this" "" { target *-*-* } .-1 } + +const int *x = &S<0>::a; Jakub