[Bug c++/83271] const variable previously declared "extern" results in "weak declaration must be public" error

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 4 19:09:00 GMT 2017


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That diagnostics is emitted from the attribute handling, before the decls is
merged with the previous extern const int x; decl, so it indeed isn't
TREE_PUBLIC.
So, this doesn't really look easy to fix, we'd need to postpone the weak
attribute processing until later, or look up from the attribute handling code
in the FE whether it has been defined already during the attribute processing,
or temporarily set TREE_PUBLIC bits on the constants around the generic
processing and then make sure to call it again once we can finalize it if it
isn't TREE_PUBLIC but is DECL_WEAK.

I must say I fail to see usefulness of adding the attribute to the definition
rather than declaration though.


More information about the Gcc-bugs mailing list