This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Diagnose static data members in anon ns which are used, but weren't defined (PR c++/34094)

Jakub Jelinek wrote:
The important difference is DECL_EXTERNAL, but as it is
DECL_NOT_REALLY_EXTERN, cp_wrap_global_declarations wants to clear that.
DECL_NONLOCAL is a FE private flag in this case.

Instead of issuing the error we could just not set DECL_EXTERNAL for it:

+         if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl)
+             && !(TREE_CODE (decl) == VAR_DECL
+                   && DECL_NONLOCAL (decl)
+                   && DECL_CLASS_SCOPE_P (decl)
+                   && DECL_INITIAL (decl) == NULL_TREE
+                   && type_visibility (DECL_CONTEXT (decl)) == VISIBILITY_ANON))

A static data member that has not yet been defined out-of-class has DECL_IN_AGGR_P set. In that case, we should leave DECL_EXTERNAL set. I don't think we need the other tests.

> But it is hard to have a g++.dg testcase
for that, plus I thought when the compiler can detect the bug, it is better
to report it than to leave it for ld.

Sure. If we're leaving DECL_EXTERNAL set, and the static data member is !TREE_PUBLIC (and DECL_INITIAL is NULL_TREE) it makes sense to complain like we do for static functions that are declared but not defined.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]