Modify

Ticket #5522 (closed Patches: wontfix)

Opened 3 years ago

Last modified 12 days ago

[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

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

Change History

Changed 3 years ago by sefi@…

Testcase

Changed 3 years ago by sefi@…

Warning output

comment:1 Changed 3 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 3 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 8 weeks 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 8 weeks ago by anonymous

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

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

comment:5 in reply to: ↑ 3 Changed 12 days ago by steven_watanabe

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

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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.