<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:59:34 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-558] &apos;legacy&apos; crashes on mongo::client::initialize() when using g++ and -std=c++11</title>
                <link>https://jira.mongodb.org/browse/CXX-558</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;Simplest possible code:&lt;br/&gt;
#include &quot;mongo/client/dbclient.h&quot; // for the driver&lt;/p&gt;

&lt;p&gt;int main() &lt;/p&gt;
{
  mongo::client::initialize();
  return 0;
}

&lt;p&gt;compilled with:&lt;br/&gt;
g++ mongo_crash.cc -std=c++11 -pthread -lmongoclient -lboost_thread-mt -lboost_system -lboost_regex -o mongo_crash&lt;/p&gt;

&lt;p&gt;causes segfault in mongo::client::initialize(). gdb says its somewhere in the ~Options(), but I don&apos;t understand what&apos;s going on. Without -std=c++11 everything works.&lt;/p&gt;

&lt;p&gt;The driver sources have been cloned out and built few days ago.&lt;/p&gt;</description>
                <environment></environment>
        <key id="189537">CXX-558</key>
            <summary>&apos;legacy&apos; crashes on mongo::client::initialize() when using g++ and -std=c++11</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="adam.midvidy">Adam Midvidy</assignee>
                                    <reporter username="bzaborow">Bartosz Zaborowski</reporter>
                        <labels>
                    </labels>
                <created>Sat, 14 Mar 2015 02:04:26 +0000</created>
                <updated>Tue, 24 Mar 2015 15:42:17 +0000</updated>
                            <resolved>Sat, 14 Mar 2015 12:04:42 +0000</resolved>
                                    <version>legacy-1.0.1</version>
                                                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="862363" author="kobolog" created="Tue, 24 Mar 2015 15:42:17 +0000"  >&lt;p&gt;I agree that that would probably be not the only issue around mixed mode builds, so yeah, makes sense.&lt;/p&gt;</comment>
                            <comment id="861573" author="acm" created="Mon, 23 Mar 2015 22:23:59 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=kobolog&quot; class=&quot;user-hover&quot; rel=&quot;kobolog&quot;&gt;kobolog&lt;/a&gt; -&lt;/p&gt;

&lt;p&gt;Part of the issue is that Boost itself does not guarantee that its own types are ABI stable between C&amp;#43;&amp;#43;03 and C&amp;#43;&amp;#43;11 builds. Given that we are dependent on Boost in our interface, we require that the application, the driver, and boost all be compiled in the same mode. In theory, we might be able to make it work, but given that this is the legacy driver, we have opted not to invest further effort in supporting mixed mode builds.&lt;/p&gt;</comment>
                            <comment id="861564" author="kobolog" created="Mon, 23 Mar 2015 22:03:44 +0000"  >&lt;p&gt;So it&apos;s not &quot;Works as Designed&quot;, to be honest =)&lt;/p&gt;</comment>
                            <comment id="861562" author="kobolog" created="Mon, 23 Mar 2015 22:00:45 +0000"  >&lt;p&gt;I just encountered the same issue. In fact, it has nothing to do with C++ ABI changes. The reason for this crash is in &lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/stdx/functional.h&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;src/mongo/stdx/functional.h&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&#8212; For non-C++ 11 builds you typedef &lt;tt&gt;stdx::function&amp;lt;T&amp;gt;&lt;/tt&gt; to be &lt;tt&gt;boost::function&amp;lt;T&amp;gt;&lt;/tt&gt;.&lt;br/&gt;
&#8212; For C++ 11 builds you typedef it to be &lt;tt&gt;std::function&amp;lt;T&amp;gt;&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;What happens is that in a driver built w/o C++ 11 support the &lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/client/options.h#L234&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;_logAppender&lt;/tt&gt;&lt;/a&gt; member of &lt;tt&gt;mongo::Options&lt;/tt&gt; compiles to be a &lt;tt&gt;boost::function&amp;lt;T&amp;gt;&lt;/tt&gt; type, while the code using that driver and compiled with C++ 11 support sees it as &lt;tt&gt;std::function&amp;lt;T&amp;gt;&lt;/tt&gt; type. Since the destructor for &lt;tt&gt;mongo::Options&lt;/tt&gt; is implicitly-defined, it&apos;s being generated when the actual project using the driver is being built, which in turn produces a code that uses &lt;tt&gt;std::function&amp;lt;T&amp;gt;&lt;/tt&gt; destructor to destroy a &lt;tt&gt;boost::function&amp;lt;T&amp;gt;&lt;/tt&gt; object, and that&apos;s when shit hits the fan.&lt;/p&gt;

&lt;p&gt;Implementing an explicit destructor for &lt;tt&gt;mongo::Options&lt;/tt&gt; would solve this problem for everyone w/o any work on the user&apos;s side.&lt;/p&gt;</comment>
                            <comment id="852293" author="bzaborow" created="Sat, 14 Mar 2015 22:07:10 +0000"  >&lt;p&gt;Great thanks for the answer, the first option seems ideal. I don&apos;t know why I didn&apos;t hit on it by myself&lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;. I would really like to use the new C++ 11 driver, but as far as I understand it is still not stable. What I need is completely stable API in a perspective of at least a few years. The software I&apos;m working on will be maintained by me not longer than a year counting from now, but must be usable without much effort for some ten years.&lt;/p&gt;</comment>
                            <comment id="852204" author="adam.midvidy" created="Sat, 14 Mar 2015 12:02:38 +0000"  >&lt;p&gt;So if you&apos;re checking before build time if the compiler supports Cxx11, you can literally try compiling a dummy file with --std=c++11 and seeing if it works. That&apos;s how we do it in SCons when building the legacy driver.&lt;/p&gt;

&lt;p&gt;see: &lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/blob/legacy/SConstruct#L1307&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/blob/legacy/SConstruct#L1307&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to check what version of C++ you are building with at compile time, you can use the &apos;_cplusplus&apos; macro. See this page for details &lt;a href=&quot;https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As an aside, if you are already using C++ 11, you should take a look at our new C++ 11 driver, which can be found on the &apos;master&apos; branch of the repository: &lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/tree/master&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/tree/master&lt;/a&gt;. It presents a much nicer interface than the old driver, and includes a new BSON library as well. It&apos;s not yet production ready, but we would like people to experiment with it.&lt;/p&gt;

&lt;p&gt;Here is a blog post that gives an overview of it: &lt;a href=&quot;https://www.mongodb.com/blog/post/introducing-new-c-driver&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://www.mongodb.com/blog/post/introducing-new-c-driver&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="852191" author="bzaborow" created="Sat, 14 Mar 2015 10:57:30 +0000"  >&lt;p&gt;Oh, right, I didn&apos;t add the --c++ 11=on switch. Now it works. Thanks for the help. But there is another question: how can I check (using autotools, CMake etc) whether a user building my software has a c++ 11 version or a c++98? I see a new mongo/config.h slightly differs form the old one, but relying on internals like  &quot;#define MONGO_HAVE_CXX11_ATOMICS 1&quot; seems not to be a clean solution.&lt;/p&gt;</comment>
                            <comment id="852158" author="adam.midvidy" created="Sat, 14 Mar 2015 03:35:01 +0000"  >&lt;p&gt;Hi Bartosz,&lt;/p&gt;

&lt;p&gt;I am sorry to hear you are having trouble with the legacy driver.  What flags did you compile the driver with? &lt;/p&gt;

&lt;p&gt;If you are building your application with C++ 11, you will need to compile the driver with C++ 11 as well. As it turns out, the ABI of the C++ 11 version of libstdc++ changed from the previous c++98 compatible version - you can read more about it here: &lt;a href=&quot;https://gcc.gnu.org/wiki/Cxx11AbiCompatibility&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gcc.gnu.org/wiki/Cxx11AbiCompatibility&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Adam&lt;/p&gt;
</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs74ev:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>