[CXX-878] max_time->count(), seconds.count() ambiguous Created: 25/Mar/16  Updated: 19/Sep/16  Resolved: 16/Jun/16

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: 3.0.0
Fix Version/s: 3.0.2

Type: Bug Priority: Major - P3
Reporter: Allan Bazinet Assignee: David Golden
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CXX-956 Compile error with clang/libc++ on Li... Closed

 Description   

When compiling on CentOS with clang 3.7.1, using the modern c++ library, i.e., using CXXFLAGS="std=c+11 -stdlib=libc+", use of options.max_time()>count() in collection.cpp and seconds.count() in modify_collection.cpp are found to be ambiguous by the compiler.

In the first case of the 4 uses of options.max_time()->count() in collection.cpp, count() is a signed integral of at least 45 bits. In the case of the single seconds.count() in modify_collection.cpp, count() is a signed integral of at least 35 bits.

Thus, it would seem that wrapping these in bsoncxx:types:b_int64 is the right thing to do, and it does in our case prevent the compiler from erroring out on the ambiguity, but we're just trying the non-legacy library for the first time, and thus aren't sure if this is an ideal approach.



 Comments   
Comment by Githook User [ 16/Jun/16 ]

Author:

{u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}

Message: CXX-878 Wrap std::chrono command options as b_int64
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/a710c8c81f5dcde8057be83d333e4c5a738620bf

Comment by David Golden [ 07/Jun/16 ]

https://github.com/mongodb/mongo-cxx-driver/pull/492

Comment by Andrew Morrow (Inactive) [ 30/Mar/16 ]

alb FYI see CXX-880 where the chrono conversion issues are also a problem on FreeBSD. I'm hoping to issue 3.0.1 of the C++11 driver today or tomorrow, and I don't want to delay it further as it already contains some important build fixes, but I will make this issue a priority for the upcoming 3.0.2 release.

Comment by Allan Bazinet [ 25/Mar/16 ]

From the diagnostic, it's finding that the long long type used for the time rep is convertible to:

void append(bool value);
void append(double value);
void append(std::int32_t value);
void append(std::int64_t value);

And it's unclear as to the desired one. The relevant section of the standard is 13.3, but I've never managed to stay awake long enough to make it all the way through it; I'd guess this is 13.3.3.1/10.

And, as mentioned, our workaround for this is, using modify_collection.cpp as an example:

<< "expireAfterSeconds" << bsoncxx::types::b_int64

{seconds.count()}

<< finalize);

Comment by Allan Bazinet [ 25/Mar/16 ]

In the interest of brevity I'll just provide the output from modify_collection.cpp as a representative sample, as it's the same issue in collection.cpp.

[alb@Archon build]$ clang --version
clang version 3.7.1 (tags/RELEASE_371/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
 
Scanning dependencies of target mongocxx
[ 20%] Building CXX object src/mongocxx/CMakeFiles/mongocxx.dir/options/modify_collection.cpp.o
In file included from /home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/mongocxx/options/modify_collection.cpp:17:
In file included from /home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/stream/document.hpp:18:
In file included from /home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/stream/key_context.hpp:19:
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/stream/value_context.hpp:70:16: error: call to member function 'append'
      is ambiguous
        _core->append(std::forward<T>(t));
        ~~~~~~~^~~~~~
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/mongocxx/options/modify_collection.cpp:39:55: note: in instantiation of function template
      specialization
      'bsoncxx::v_noabi::builder::stream::value_context<bsoncxx::v_noabi::builder::stream::key_context<bsoncxx::v_noabi::builder::stream::closed_context>
      >::operator<<<long long>' requested here
                              << "expireAfterSeconds" << seconds.count() << finalize);
                                                      ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:243:10: note: candidate function
    void append(bool value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:248:10: note: candidate function
    void append(double value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:253:10: note: candidate function
    void append(std::int32_t value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:258:10: note: candidate function
    void append(std::int64_t value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:115:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_double' for 1st argument
    void append(const types::b_double& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:120:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_utf8' for 1st argument
    void append(const types::b_utf8& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:125:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_document' for 1st argument
    void append(const types::b_document& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:130:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_array' for 1st argument
    void append(const types::b_array& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:135:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_binary' for 1st argument
    void append(const types::b_binary& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:140:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_undefined' for 1st argument
    void append(const types::b_undefined& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:145:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_oid' for 1st argument
    void append(const types::b_oid& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:150:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_bool' for 1st argument
    void append(const types::b_bool& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:155:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_date' for 1st argument
    void append(const types::b_date& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:160:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_null' for 1st argument
    void append(const types::b_null& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:165:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_regex' for 1st argument
    void append(const types::b_regex& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:170:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_dbpointer' for 1st argument
    void append(const types::b_dbpointer& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:175:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_code' for 1st argument
    void append(const types::b_code& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:180:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_symbol' for 1st argument
    void append(const types::b_symbol& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:185:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_codewscope' for 1st argument
    void append(const types::b_codewscope& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:190:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_int32' for 1st argument
    void append(const types::b_int32& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:195:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_timestamp' for 1st argument
    void append(const types::b_timestamp& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:200:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_int64' for 1st argument
    void append(const types::b_int64& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:205:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_minkey' for 1st argument
    void append(const types::b_minkey& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:210:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::b_maxkey' for 1st argument
    void append(const types::b_maxkey& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:215:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const types::value' for 1st argument
    void append(const types::value& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:220:10: note: candidate function not viable: no known conversion
      from 'long long' to 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') for 1st argument
    void append(std::string str);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:225:10: note: candidate function not viable: no known conversion
      from 'long long' to 'stdx::string_view' (aka 'basic_string_view<char>') for 1st argument
    void append(stdx::string_view str);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:263:10: note: candidate function not viable: no known conversion
      from 'long long' to 'const bsoncxx::v_noabi::oid' for 1st argument
    void append(const oid& value);
         ^
/home/alb/Development/Fusion/Depend/mongo-cxx-driver-master/src/bsoncxx/builder/core.hpp:234:25: note: candidate template ignored: could not match 'T *'
      against 'long long'
    BSONCXX_INLINE void append(T* v) {
                        ^
1 error generated.
make[2]: *** [src/mongocxx/CMakeFiles/mongocxx.dir/options/modify_collection.cpp.o] Error 1
make[1]: *** [src/mongocxx/CMakeFiles/mongocxx.dir/all] Error 2
make: *** [all] Error 2

Comment by Andrew Morrow (Inactive) [ 25/Mar/16 ]

Hi alb - Thank you for the bug report. Could you please provide the compiler output stating the ambiguities?

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