Modify

Opened 6 years ago

Closed 3 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@… 6 years ago.
Testcase
output.log (984 bytes) - added by sefi@… 6 years ago.
Warning output

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by sefi@…

Testcase

Changed 6 years ago by sefi@…

Warning output

comment:1 Changed 6 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: Changed 6 years ago by eric_niebler

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

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: Changed 3 years 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 3 years ago by anonymous

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

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 3 years ago by steven_watanabe

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

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.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain eric_niebler.
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.