commit 74c41e559636a78b8415467ce2ca7ea0eb641956
Author: Jason Merrill <jason@redhat.com>
Date: Tue Feb 19 16:47:22 2019 -1000
PR c++/87921 - wrong error with inline static data member.
An instantiation of an inline variable isn't defined until it's
instantiated, so don't treat it as defined just because it's inline.
* decl2.c (c_parse_final_cleanups): Don't force out uninstantiated
inline static data members.
@@ -4905,7 +4905,10 @@ c_parse_final_cleanups (void)
{
if (var_finalized_p (decl) || DECL_REALLY_EXTERN (decl)
/* Don't write it out if we haven't seen a definition. */
- || (DECL_IN_AGGR_P (decl) && !DECL_INLINE_VAR_P (decl)))
+ || (DECL_IN_AGGR_P (decl) && !DECL_INLINE_VAR_P (decl))
+ /* Or haven't instantiated it. */
+ || (DECL_TEMPLATE_INSTANTIATION (decl)
+ && !DECL_TEMPLATE_INSTANTIATED (decl)))
continue;
import_export_decl (decl);
/* If this static data member is needed, provide it to the
new file mode 100644
@@ -0,0 +1,16 @@
+// PR c++/87921
+// { dg-do compile { target c++17 } }
+
+template <class H>
+struct X
+{
+ static inline long x[] = { 1L };
+ long foo () { return x[0]; }
+};
+
+void
+bar ()
+{
+ class L {};
+ X<L> v {};
+}