[CXX-1423] Missing include for <cassert> in tests Created: 16/Aug/17  Updated: 28/Oct/23  Resolved: 21/Aug/17

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: 3.1.2
Fix Version/s: 3.1.3

Type: Bug Priority: Major - P3
Reporter: Alexander [X] Assignee: Samuel Rossi (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CXX-1422 Does not finish building, error somew... Closed

 Description   

I try to use MongoDB C Driver version 1.7.0 in Debian Stretch like described in this instruction: https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation
This is was fail. But with previous version (1.6.3) everything work fine.

How to reproduce the issue

Step 0: To emulate my environment you can use docker. If you have't docker yet, you can install it like described here: https://docs.docker.com/engine/installation/

Step 1: Create an empty directory, then create Dockerfile inside and copy/paste into it this content:

FROM debian:stretch
ADD https://github.com/mongodb/mongo-c-driver/releases/download/1.6.3/mongo-c-driver-1.6.3.tar.gz /
ADD https://github.com/mongodb/mongo-cxx-driver/archive/r3.1.2.tar.gz /
RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
libboost-all-dev \
libmagick++-dev \
libsasl2-dev \
libssl-dev \
pkg-config && \
cd /mongo-c-driver-1.6.3 && \
./configure --disable-automatic-init-and-cleanup && \
make && \
make install && \
make clean && \
cd / && \
cd /mongo-cxx-driver-r3.1.2/build && \
cmake -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
make && \
make install && \
make clean && \
apt-get clean

Step 2: Build it with command
sudo docker build . -t test

In my case there are no error break the process (but tonns of warnings) and I succesfully got docker image with both drivers installed.

Step 3: Switch the version by command (I change version for first driver only):
sed -i 's/1.6.3/1.7.0/g' Dockerfile

Step 4: Try to repeat Step 2. In my case first driver builded and installes successfully, but second driver failed to build with error:

In file included from /mongo-cxx-driver-r3.1.2/src/mongocxx/private/libmongoc.hh:19:0,
from /mongo-cxx-driver-r3.1.2/src/third_party/catch/include/helpers.hpp:17,
from /mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:16:
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh: In instantiation of 'void mongocxx::v_noabi::test_util::mock<R (Args ...)>::active_instance(mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance*) [with R = _mongoc_bulk_operation_t*; Args =

{bool}]':
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:153:24: required from 'std::unique_ptr<mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance> mongocxx::v_noabi::test_util::mock<R (Args ...)>::create_instance() [with R = _mongoc_bulk_operation_t*; Args = {bool}

]'
/mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:30:68: required from here
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:173:15: error: 'assert' was not declared in this scope
assert(!current); // It is impossible to create two instances in a single thread
~~~~~^~~~~~~~~
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh: In instantiation of 'void mongocxx::v_noabi::test_util::mock<R (Args ...)>::active_instance(mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance*) [with R = void; Args = {_mongoc_bulk_operation_t*}]':
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:153:24: required from 'std::unique_ptr<mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance> mongocxx::v_noabi::test_util::mock<R (Args ...)>::create_instance() [with R = void; Args = {_mongoc_bulk_operation_t*}]'
/mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:57:71: required from here
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:173:15: error: 'assert' was not declared in this scope
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh: In instantiation of 'void mongocxx::v_noabi::test_util::mock<R (Args ...)>::active_instance(mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance*) [with R = void; Args = {_mongoc_bulk_operation_t*, const _bson_t*}]':
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:153:24: required from 'std::unique_ptr<mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance> mongocxx::v_noabi::test_util::mock<R (Args ...)>::create_instance() [with R = void; Args = {_mongoc_bulk_operation_t*, const _bson_t*}]'
/mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:189:77: required from here
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:173:15: error: 'assert' was not declared in this scope
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh: In instantiation of 'void mongocxx::v_noabi::test_util::mock<R (Args ...)>::active_instance(mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance*) [with R = bool; Args = {_mongoc_bulk_operation_t*, const _bson_t*, const _bson_t*, const _bson_t*, _bson_error_t*}]':
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:153:24: required from 'std::unique_ptr<mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance> mongocxx::v_noabi::test_util::mock<R (Args ...)>::create_instance() [with R = bool; Args = {_mongoc_bulk_operation_t*, const _bson_t*, const _bson_t*, const _bson_t*, _bson_error_t*}]'
/mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:197:91: required from here
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:173:15: error: 'assert' was not declared in this scope
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh: In instantiation of 'void mongocxx::v_noabi::test_util::mock<R (Args ...)>::active_instance(mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance*) [with R = bool; Args = {_mongoc_bulk_operation_t*, const _bson_t*, const _bson_t*, _bson_error_t*}]':
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:153:24: required from 'std::unique_ptr<mongocxx::v_noabi::test_util::mock<R (Args ...)>::instance> mongocxx::v_noabi::test_util::mock<R (Args ...)>::create_instance() [with R = bool; Args = {_mongoc_bulk_operation_t*, const _bson_t*, const _bson_t*, _bson_error_t*}]'
/mongo-cxx-driver-r3.1.2/src/mongocxx/test/bulk_write.cpp:265:91: required from here
/mongo-cxx-driver-r3.1.2/src/mongocxx/test_util/mock.hh:173:15: error: 'assert' was not declared in this scope
make[2]: *** [src/mongocxx/test/CMakeFiles/test_driver.dir/bulk_write.cpp.o] Error 1
src/mongocxx/test/CMakeFiles/test_driver.dir/build.make:110: recipe for target 'src/mongocxx/test/CMakeFiles/test_driver.dir/bulk_write.cpp.o' failed
make[1]: *** [src/mongocxx/test/CMakeFiles/test_driver.dir/all] Error 2
CMakeFiles/Makefile2:779: recipe for target 'src/mongocxx/test/CMakeFiles/test_driver.dir/all' failed
make: *** [all] Error 2
Makefile:138: recipe for target 'all' failed

What's I doing wrong?



 Comments   
Comment by Githook User [ 21/Aug/17 ]

Author:

{'email': 'rjgebis@autobon.ai', 'name': 'Robert J. Gebis'}

Message: CXX-1423 Add missing include for <cassert> in mock tests
Branch: bugfix/3.1.x
https://github.com/mongodb/mongo-cxx-driver/commit/409182980a1b3287632b2754c846320174fc91c7

Comment by Hannes Magnusson [ 16/Aug/17 ]

The cdriver accidentally leaked assert.h includes in its public headers and was fixed as part of https://jira.mongodb.org/browse/CDRIVER-2005

Unfortunately it looks like some projects, like mongocxx, didn't explicitly include assert.h when they themselfs required it.
Now that assert.h isn't included by mongoc headers, these projects hit compiler errors like:

error: 'assert' was not declared in this scope

The 3.2.0 release of the mongocxx driver, which depends on mongoc 1.7.0 will have this fixed.
The 3.1.x release of the mongocxx driver needs a fix, probably like https://github.com/mongodb/mongo-cxx-driver/pull/587

I'm moving this ticket to the CXX project

Generated at Wed Feb 07 22:02:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.