https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105595

Arsen Arsenović <arsen at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=53184

--- Comment #6 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
(In reply to dennis-hezel from comment #5)
> > naturally, if you never include this file twice, it should be okay
> 
> That is exactly the point. Whenever a file with your `namespace { struct X
> {}; }` example or the coroutine example is included into another file we get
> this warning. It is correct that we may only include the file into exactly
> one TU. But we get the warning even if we uphold that which is what I would
> like to see fixed.

right, but that's already the case for the general Wsubobject-linkage, not just
the coroutine case.  fixing that would probably require some integration with
LTO.  I have a one-line patch which should suppress this warning correctly for
coroutines (i.e. without impacting program correctness, if I'm not mistaken):

modified   gcc/cp/coroutines.cc
@@ -4669,6 +4669,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree
*destroyer)
   tree fr_name = get_fn_local_identifier (orig, "Frame");
   tree coro_frame_type = xref_tag (record_type, fr_name);
   DECL_CONTEXT (TYPE_NAME (coro_frame_type)) = current_scope ();
+  TREE_PUBLIC (TYPE_NAME (coro_frame_type)) = false;
   tree coro_frame_ptr = build_pointer_type (coro_frame_type);
   tree act_des_fn_type
     = build_function_type_list (void_type_node, coro_frame_ptr, NULL_TREE);

we're referencing a compiler internal in the diagnostic, so that's not great
already, and needs fixing at least.  in addition, a check more tuned for
functions should probably be one that actually emits this warning even for
coros, so we should probably get rid of it anyway.

> Here is a more realistic example program also featuring a similar, regular
> function for comparison. Note how the function does not trigger the warning.
> 
> https://godbolt.org/z/56bTsMsee
right, but that's because the code that emits it doesn't scan functions, and
coroutines happen to have a data structure attached to them (afaict the same
concern applies to functions also).  the little reproducer I attached at the
end of my comment is more representative probably, and does emit the warning.

Reply via email to