# Ticket #5522(closed Patches: wontfix)

Opened 4 years ago

## [foreach] Warning with gcc-4.6.0 and -Wconversion

Reported by: Owned by: sefi@… eric_niebler To Be Determined foreach Boost Development Trunk Problem

### 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.

## Change History

Testcase

Warning output

### comment:1 Changed 4 years ago by anonymous

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 follow-up: ↓ 4 Changed 4 years ago by eric_niebler

• Status changed from new to closed
• Resolution set to wontfix

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 follow-up: ↓ 5 Changed 19 months ago by anonymous

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


### comment:4 in reply to: ↑ 2 Changed 19 months ago by anonymous

• Status changed from closed to reopened
• Type changed from Bugs to Patches
• Resolution wontfix deleted

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

### comment:5 in reply to: ↑ 3 Changed 17 months ago by steven_watanabe

• Status changed from reopened to closed
• Resolution set to wontfix

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.

View