symbols visibility + inline virtual desctructors => dynamic_cast<DOMElement> 
failure in user code
-------------------------------------------------------------------------------------------------

         Key: XERCESC-1550
         URL: http://issues.apache.org/jira/browse/XERCESC-1550
     Project: Xerces-C++
        Type: Bug
  Components: Build  
    Versions: 2.7.0    
 Environment: OSX GCC 4.0
    Reporter: Miklos Fazekas


We have a code like this:

XMLTest.cpp:

         DOMNodeList* nodes = doc->getElementsByTagName(L("TABLE"));
        if ( int i=nodes->getLength() == 1 )
        {
                DOMNode* att_node = nodes->item(0);
                DOMElement* att_element = dynamic_cast<DOMElement*>(att_node);
                   printf ("Element:%d\n", att_element);
        } 

On OSX when we use symbols visibility attrbiutes, the dynamic_cast returns 0.

The issue seems to be the following:

1. There is two RTTI entries generated for the class. [According to C++ the 
RTTI is generated at the place of the implementation of first virtual function.]
2. One RTTI entry is marked with visibility("hidden") and found in usercode. 
The other one is marked with visibility("default").
3. It seems that if there's an RTTI marked as "hidden" the dynamic_cast can't 
work. Quote from http://gcc.gnu.org/wiki/Visibility :
" Symbol visibility is "default" by default but if it encounters just one 
definition with it hidden - just one - that typeinfo symbol becomes permanently 
hidden (remember the C++ standard's ODR - one definition rule).  " 

class CDOM_EXPORT DOMElement: public DOMNode {
public:
    ...
    virtual ~DOMElement() {};
    ...
}

Possible fixes:
a.) Implement the destructor in a C++ file, compiled into xerces c++. This 
would avoid multiple RTTI .
b.) set CDOM_EXPORT to visibility("default") even when it's used from the user 
code.

We choose a.) as it seems to be a nicer solution. 
[By the way i do not see why symbols visibility of GCC should work that crappy 
with dynamic_cast, but there's not too much i could do there.]

References:
http://gcc.gnu.org/wiki/Visibility


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to