Opened 11 years ago

Closed 9 years ago

#5522 closed Patches (wontfix)

[foreach] Warning with gcc-4.6.0 and -Wconversion

Reported by: sefi@… Owned by: Eric Niebler
Milestone: To Be Determined Component: foreach
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

gcc-4.6.0 made Boost.foreach unusable in 1.46.1 because the rvalue detection no longer works. Now, there is a fix in trunk for it but it has a nasty side effect, namely a warning that is emitted whenever foreach is used with an rvalue and -Wconversion is turned on. Sadly, this warning cannot be ignored by including Boost with -isystem because the code is generated by a macro, obviously.

I would be glad if this could be fixed somehow because -Wconversion is a crucial warning option to me.

Attachments (2)

test.cpp (300 bytes ) - added by sefi@… 11 years ago.
Testcase
output.log (984 bytes ) - added by sefi@… 11 years ago.
Warning output

Download all attachments as: .zip

Change History (7)

by sefi@…, 11 years ago

Attachment: test.cpp added

Testcase

by sefi@…, 11 years ago

Attachment: output.log added

Warning output

comment:1 by anonymous, 11 years ago

See also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021#c12, where a related problem is discussed, the final resolution is pointing to a bug in BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION.

comment:2 by Eric Niebler, 11 years ago

Resolution: wontfix
Status: newclosed

I believe gcc is warning about perfectly valid code. There is no other way to detect const rvalues in C++98 that I'm aware of. I don't know how to fix this, and using _Pragma to suppress the warning didn't work. I'm sorry, I don't think this is fixable.

If you come up with a patch, please reopen this ticket. Thanks.

comment:3 by anonymous, 9 years ago

For what it's worth, I found a workaround this way. I'm assuming the compiler will optimize out the vLINE variables. The LINE concatenation is required if you have multiple FOREACH calls with\in the same scope.

#if defined(__GNUC__)
#define M_FOREACH(elem, vec)    M_FOREACH_W_LINE(elem,vec,__LINE__)
#define M_FOREACH_W_LINE(elem, vec, n) M_FOREACH_CONCAT_VAR(elem, vec, n)
#define M_FOREACH_CONCAT_VAR(elem, vec, n)              \
        __typeof__(vec) v ## n = vec;                   \
        BOOST_FOREACH(elem, v ## n)

#else
#define M_FOREACH(elem, vec)                            \
        BOOST_FOREACH(elem, vec)
#endif

in reply to:  2 comment:4 by anonymous, 9 years ago

Resolution: wontfix
Status: closedreopened
Type: BugsPatches

Replying to eric_niebler:

I believe gcc is warning about perfectly valid code. There is no other way to detect const rvalues in C++98 that I'm aware of. I don't know how to fix this, and using _Pragma to suppress the warning didn't work. I'm sorry, I don't think this is fixable.

If you come up with a patch, please reopen this ticket. Thanks.

Reopened, see previous comment

in reply to:  3 comment:5 by Steven Watanabe, 9 years ago

Resolution: wontfix
Status: reopenedclosed

Replying to anonymous:

I'm assuming the compiler will optimize out the vLINE variables.

It's extremely unlikely. This workaround is also completely unsuitable for inclusion in the library.

Note: See TracTickets for help on using tickets.