Opened 13 years ago

Closed 13 years ago

#3603 closed Bugs (fixed)

Fix warnings when compiling test cases

Reported by: s.ochsenknecht@… Owned by: Vladimir Prus
Milestone: Boost 1.42.0 Component: program_options
Version: Boost 1.40.0 Severity: Cosmetic
Keywords: Cc: mateusz@…

Description

I attached a patch which fixes some compile warnings on:

Linux Trudheim 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/Linux
g++ (Ubuntu 4.4.1-4ubuntu8) 4.4.1
bjam gcc warnings=all cxxflags=-Wextra

I still get a warning, but this one comes from another boost header:

../../../boost/integer.hpp:145:24: warning: use of C99 long long integer constant

Attachments (4)

fix_warnings.patch (13.3 KB ) - added by s.ochsenknecht@… 13 years ago.
patch
any_cast_warning.patch (575 bytes ) - added by s.ochsenknecht@… 13 years ago.
patch
any_cast_warning.2.patch (566 bytes ) - added by Sascha Ochsenknecht 13 years ago.
patch
any_warning.cpp (378 bytes ) - added by Sascha Ochsenknecht 13 years ago.
test case

Download all attachments as: .zip

Change History (14)

by s.ochsenknecht@…, 13 years ago

Attachment: fix_warnings.patch added

patch

comment:1 by Vladimir Prus, 13 years ago

(In [57535]) Fix warnings.

Addresses #3603. Patch from Sascha Ochsenknecht.

comment:2 by Vladimir Prus, 13 years ago

Sascha, I have checked in this patch. I'll leave the issue open until the warnings from integer is resolved somehow -- and I'm posting an email about that.

comment:3 by mloskot <mateusz@…>, 13 years ago

Cc: mateusz@… added

by s.ochsenknecht@…, 13 years ago

Attachment: any_cast_warning.patch added

patch

comment:4 by anonymous, 13 years ago

Type: PatchesBugs

I got some other warnings when compiling options_description_test.cpp:

../../../boost/any.hpp: In member function ‘void boost::program_options::typed_value<T, charT>::notify(const boost::any&) const [with T = double, charT = char]’:
options_description_test.cpp:182:   instantiated from here
../../../boost/any.hpp:216: warning: type qualifiers ignored on function return type
../../../boost/any.hpp: In member function ‘void boost::program_options::typed_value<T, charT>::notify(const boost::any&) const [with T = int, charT = char]’:
options_description_test.cpp:182:   instantiated from here
../../../boost/any.hpp:216: warning: type qualifiers ignored on function return type

Probably these warnings point to a real bug (changed type to "bug" until it is clear).

I compiled "by-hand" with:

g++ options_description_test.cpp \
   -g -Wall -Wextra -pedantic -I../../.. -L/my/private/libdir -lboost_program_options -o a.out 

I'm not quite sure, but I think any_cast is used in a wrong way. I added any_cast_warning.patch which should solve this problem ... but please review!

Thanks

comment:5 by Vladimir Prus, 13 years ago

options_description_test.cpp does not even have line 182 in my copy. And I don't get the warning either. So, how do I reproduce this?

comment:6 by Vladimir Prus, 13 years ago

Hmm, the any_cast that reports the error is the one taking reference to any, while The code in typed_value::notify is supposed to call the one taking pointer. I am completely confused.

comment:7 by anonymous, 13 years ago

Looking deeper to it, confuses me also :-(. Will comment on that asap.

by Sascha Ochsenknecht, 13 years ago

Attachment: any_cast_warning.2.patch added

patch

by Sascha Ochsenknecht, 13 years ago

Attachment: any_warning.cpp added

test case

comment:8 by Sascha Ochsenknecht, 13 years ago

I guess I found the problem, my first approach was due to misunderstanding. Sorry for confusion.

Here is what the gcc manual says about this warning:

Warn if the return type of a function has a type qualifier such as const. For ISO C such a type qualifier has no effect, since the value returned by a function is not an lvalue.

So, the any cast is supposed to return "const T* const" due to the template parameter <const T>. Here is declaration of the any_cast:

template<typename ValueType> const ValueType * any_cast(const any * operand);

So, the line in detail/value_semantic.hpp has to be changed from:

const T* value = boost::any_cast<const T>(&value_store);

to

const T* value = boost::any_cast<T>(&value_store);

I attached a new any_cast_warning.2.patch and a test case any_warning.cpp

Cheers, Sascha

comment:9 by Sascha Ochsenknecht, 13 years ago

The any_cast issue is resolved, see #2562

This ticket is still open due to the integer issue which is still not resolved.

comment:10 by Sascha Ochsenknecht, 13 years ago

Milestone: Boost 1.41.0Boost 1.42.0
Resolution: fixed
Status: newclosed

The integer issue seems to be resolved on trunk, so I close the ticket. I could not see any warning currently (using bjam gcc warnings=all cxxflags=-Wextra)

Note: See TracTickets for help on using tickets.