[CDRIVER-1179] --enable-maintainer-flags doesn't add -Wdeclaration-after-statement Created: 25/Mar/16  Updated: 10/Aug/16  Resolved: 09/May/16

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

Type: Bug Priority: Major - P3
Reporter: Hannes Magnusson Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

VS2010 isn't a fan of variable declarations after statements, so requires them to be declared at the start of a scope.

For that, we have -Wdeclaration-after-statement as part of our --enable-maintainer-flags both in libbson and mongoc.

Unfortunately, this flag makes no sense in C++ where this is completely valid.
Our m4 function that checks if the various flags are supported by the current compiler also check if the flag is valid under CXX.
If it isn't, it won't add the flag to MAINTAINER_FLAGS.



 Comments   
Comment by Githook User [ 09/May/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1179 don't disable flags g++ rejects

In ./autogen.sh --enable-maintainer-flags, for some reason we check if
both gcc and g++ accept each flag, and disable the flag if not. Thus we
disabled -Wdeclaration-after-statement, which is a useful flag to have
turned on when compiling C.

We don't use g+, so don't check flags for g+ compatibility.
Branch: master
https://github.com/mongodb/libbson/commit/f571948104457fc46ddea7798ef34e82ed626c13

Comment by Githook User [ 09/May/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1179 don't disable flags g++ rejects

In ./autogen.sh --enable-maintainer-flags, for some reason we check if
both gcc and g++ accept each flag, and disable the flag if not. Thus we
disabled -Wdeclaration-after-statement, which is a useful flag to have
turned on when compiling C.

We don't use g+, so don't check flags for g+ compatibility.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/5634831ce108cd7851ae9257a5056eb96c2b1a32

Comment by A. Jesse Jiryu Davis [ 06/May/16 ]

With gcc 4.8.4 on Ubuntu Trusty:

$ ./autogen.sh --enable-maintainer-flags
...
checking whether C compiler accepts -Wdeclaration-after-statement... yes
checking whether C++ compiler accepts -Wdeclaration-after-statement... no
...

We test this flag with our custom macro that tries each flag with the C and C++ compilers:

check_cc_cxx_flag([-Wdeclaration-after-statement], [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])

Since the C++ check comes second, it overwrites the first result and disables the compiler flag. This is the only flag we use that have different outcomes for C and C++ with gcc 4.8.4.

P.S.: clang 700.1.81 on my Mac supports -Wdeclaration-after-statement in C++ mode:

checking whether C compiler accepts -Wdeclaration-after-statement... yes
checking whether C++ compiler accepts -Wdeclaration-after-statement... yes

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