[CXX-1495] Maybe uninitialized warning with GCC 7 in bsoncxx/document/value.hpp Created: 13/Jan/18  Updated: 28/Oct/23  Resolved: 22/Jan/18

Status: Closed
Project: C++ Driver
Component/s: Build
Affects Version/s: None
Fix Version/s: 3.2.0

Type: Bug Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Sara Golemon
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

When building the driver with GCC 7, the following (false positive?) error is emitted:

In file included from ../src/bsoncxx/array/value.hpp:21:0,
                 from ../src/bsoncxx/array/view_or_value.hpp:17,
                 from ../src/bsoncxx/builder/concatenate.hpp:17,
                 from ../src/bsoncxx/builder/basic/helpers.hpp:17,
                 from ../src/bsoncxx/builder/basic/sub_array.hpp:17,
                 from ../src/bsoncxx/builder/basic/impl.hpp:17,
                 from ../src/bsoncxx/builder/basic/document.hpp:17,
                 from ../src/bsoncxx/test/view_or_value.cpp:15:
../src/bsoncxx/document/value.hpp: In function 'void {anonymous}::____C_A_T_C_H____T_E_S_T____31()':
../src/bsoncxx/document/value.hpp:108:63: warning: 'copied.bsoncxx::v_noabi::document::value::_length' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return document::view{static_cast<uint8_t*>(_data.get()), _length};
                                                               ^~~~~~~
../src/bsoncxx/document/value.hpp:108:63: warning: 'moved.bsoncxx::v_noabi::document::value::_length' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return document::view{static_cast<uint8_t*>(_data.get()), _length};
                                                               ^~~~~~~

As this is a user facing header, this warning is likely to cause problems for users. We should investigate and make a determination as to whether GCC is truly warning us about something dangerous, or is being overzealous, before issuing 3.2.0.

Note that clang does not issue a warning here.



 Comments   
Comment by Githook User [ 22/Jan/18 ]

Author:

{'name': 'Sara Golemon', 'email': 'sara.golemon@mongodb.com', 'username': 'sgolemon'}

Message: CXX-1495 Explicitly initialize/reset value::_length
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/99125cb3f16e14dda7eb54df779cc25333d9e151

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