-
Notifications
You must be signed in to change notification settings - Fork 22
Mapnik Compilation warning C4172: returning address of local variable or temporary? #81
Comments
Yes, I've seen these warnings. Because they are coming out of boost (not mapnik) I had not paid much attention, but yes we should take a closer look to make sure they are not happening due to Mapnik usage. /cc @artemp |
Do these occur when karma attributes are assigned references instead of temporaries? diff --git a/src/color.cpp b/src/color.cpp
index 2dcbe76..2a35353 100644
--- a/src/color.cpp
+++ b/src/color.cpp
@@ -85,10 +85,10 @@ std::string color::to_hex_string() const
karma::generate(sink,
// begin grammar
'#'
- << right_align(2,'0')[hex[_1 = red()]]
- << right_align(2,'0')[hex[_1 = green()]]
- << right_align(2,'0')[hex[_1 = blue()]]
- << eps(alpha() < 255) << right_align(2,'0')[hex [_1 = alpha()]]
+ << right_align(2,'0')[hex[_1 = red_]]
+ << right_align(2,'0')[hex[_1 = green_]]
+ << right_align(2,'0')[hex[_1 = blue_]]
+ << eps(alpha() < 255) << right_align(2,'0')[hex [_1 = alpha_]]
// end grammar
);
return str; |
I recently left a reply on the mapnik issues thread. I think I directly caused the error when I was modifying a patch. I had left in a BOOST_SPIRIT_UNICODE pragma in I had previously tried a number of things including what you suggested but nothing seemed to stop the error, It was only when I recompared my changes to the current codebase that I realised the extra pragma was still there. I haven't closed the issue as the compiler warnings are still there even though they don't seem to have caused my problem. If it's not seen as a big deal though I don't mind if it is closed. |
I'm asking because I'm not sure what exactly Anyway, I will probably rewrite at least |
@lightmare @artemp might complain, but I'm a big 👍 :) That would allow us to drop compile time for |
@springmeyer - not so quick :) . Remember, mapnik is C++ not C !!
What? I'm not even mildly convinced by your statement but I'd like to see your |
@lightmare @springmeyer - I think |
For what it's worth, while I was trying to figure out what was causing my problem I did rewrite the
|
@jc101 - the approach above works but I prefer could you try mapnik/mapnik@3e8ee9a and see if warning are gone, pls ? |
🎯 touche! That was unfairly exaggerated, not sure why I imagined color stored as uint8_t[3] and no alpha, that would be possible in 7 lines (almost C 🍰 ) static char const xdigits[] = "0123456789abcdef";
char buf[7] = {'#'};
for (int i = 0; i < 3; ++i) {
buf[1 + 2 * i] = xdigits[(c[i] >> 4) & 15];
buf[2 + 2 * i] = xdigits[c[i] & 15];
}
return std::string(buf, 7); Here's a real, 15-line body version std::string color::to_hex_string() const
{
static char const xdigits[] = "0123456789abcdef";
char buf[9];
buf[0] = '#';
buf[1] = xdigits[(red_ >> 4) & 15];
buf[2] = xdigits[red_ & 15];
buf[3] = xdigits[(green_ >> 4) & 15];
buf[4] = xdigits[green_ & 15];
buf[5] = xdigits[(blue_ >> 4) & 15];
buf[6] = xdigits[blue_ & 15];
if (alpha_ == 255) {
return std::string(buf, 7);
}
buf[7] = xdigits[(alpha_ >> 4) & 15];
buf[8] = xdigits[alpha_ & 15];
return std::string(buf, 9);
} |
@lightmare - 👏 you get 🏆 😺 ! On a serious note - I still prefer to use boost::spirit for parsing/generating output in mapnik rather than resorting to handwriting parser/generators. I'm thinking long term stability, readability, consistency etc etc. |
@lightmare - here is a real challenge =>
It would be super awesome to fix that ^. I know you have looked already but anything else we can do to improve? In any case should we at least split |
I've been pondering handwriting spirit::qi::parser
Yea, I stopped there. Separating the operators might help, as they require different |
@artemp I tried the changes you made and the warnings are gone; fyi they still exist on two files: |
Has anyone experienced these warnings around compiling the color files (eg
css_color_grammar.cpp
;color.cpp
) when building Mapnik?warning C4172: returning address of local variable or temporary
They seem to occur in boost phoenix header files eg
meta_grammar.hpp
,actor_operator_10.hpp
etc.I suspect (following discussions over on mapnik) that they are causing access violation errors (when inline functions are enabled - mangled strings when disabled) I am experiencing with outputting the color to a hex string using the karma generator but am just wondering if other people experience these warnings too?
The text was updated successfully, but these errors were encountered: