[CDRIVER-3378] warning: ignoring attributes on template argument Created: 27/Sep/19  Updated: 27/Oct/23  Resolved: 30/Apr/20

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: 1.15.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bozana Hadzic Assignee: Kevin Albertson
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux, ubuntu 18.04, x86_64
compiler: g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0



 Description   

creating vector of bson_t pointers causes warning: "ignoring attributes on template argument ‘bson_t {aka _bson_t*}’ [-Wignored-attributes]"*

Example of code:

#include <iostream>
#include <bson.h>
#include <vector>
 
using namespace std;
 
int
main( int argc, char **argv){
    bson_t *doc = bson_new();
    bson_init( doc );    std::vector<bson_t *> v;
    v.push_back(doc);
    bson_t *doc2 = v.back();
    v.pop_back();
    bson_destroy(doc2);    return 0;
}

test_bson_vec.c:13:25: warning: ignoring attributes on template argument ‘bson_t* {aka _bson_t*}’ [-Wignored-attributes]
std::vector<bson_t *> v;



 Comments   
Comment by Kevin Albertson [ 30/Apr/20 ]

To follow up, I am able to reproduce this warning with g++ 7.5 on Ubuntu 18.04. Compiling without extra alignment does not resolve the warning, since alignment specifiers are still present (but are reduced to the size of void * instead of 128).

There is an open ticket to consider providing an option to disable alignment specifiers altogether (CDRIVER-2957), but that is not scheduled, and we may decide not to proceed with that work.

As far as I know, the warning is not harmful. Wrapping bson_t in a struct silences this warning:

typedef struct {
    bson_t bson;
} bson_wrapper;
 
int main () {
    std::vector<bson_wrapper*> v;
}

Or alternatively, -Wno-ignored-attributes could be used to ignore the warning of the dropped alignment specifier.

As an aside:

bson_t *doc = bson_new();
bson_init( doc );

Is an improper double initialization. bson_new already initializes the bson_t. Calling bson_init should only be done on a bson_t on the stack, not one created with bson_new. This ends up "converting" the bson_t into thinking it was stack allocated. So the subsequent bson_destroy does not free the bson_t struct itself, resulting in a leak.

Comment by Kevin Albertson [ 01/Apr/20 ]

Hi bozana.hadzic@g3ti.net,

Apologies for the delayed response. If this is still an issue for you, please respond with the following information.

1. Can you provide the command you are using to compile, and any additional compiler output?
2. How are you installing libmongoc? If you are building from source, I suspect this may be due to the extra alignment specifiers. It is recommended to disable those regardless. If possible, try configuring libmongoc with the cmake option -DENABLE_EXTRA_ALIGNMENT=OFF and reinstalling.

Generated at Wed Feb 07 21:17:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.