Comments (8)
I guess gcc 4.4 turned on strict aliasing by default? Or maybe the detection
just
got better; I'm not seeing any problems with gcc 4.2, even with
-fstrict-aliasing
explicitly enabled.
In any cased, I thought strict aliasing problems were a warning, not an error.
Are
you using -Werror as well?
I don't have gcc 4.4.1 handy. Can you try compiling, say, the unittests (via
'make
check'), and attaching the full output? With line numbers, it should be easy
to
diagnose the problem and, hopefully, fix it.
Original comment by [email protected]
on 8 Jan 2010 at 3:57
from gflags.
Yes, I'm using -Werror for my compiles - that's why I see the error. Otherwise,
its a
warning - which is still ugly.
Attached is a file that shows the complete output when a 'make' is done inside
the
gflags-1.2 source. You can see the relevant warnings when the unittests are
being
compiled. Here's an excerpt:
src/gflags_unittest.cc:84: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:85: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:94: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:104: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:105: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:106: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:109: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:123: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
src/gflags_unittest.cc:134: warning: dereferencing type-punned pointer will
break
strict-aliasing rules
Original comment by [email protected]
on 8 Jan 2010 at 6:45
Attachments:
from gflags.
Just a little more information to help out with fixing this bug. The line
numbers
reported by the compiler while emitting the warning correspond to the location
where
the DEFINE_string macro is used. It doesn't give the precise line within the
macro's
implementation that's causing the warning to be emitted.
So what I did was replace one of the uses of the macro DEFINE_string with its
implementation (after fixing the implementation appropriately to make it valid
outside a macro definition). The compiler reported the warning this time at the
following line within the macro's implementation:
std::string& FLAGS_##name = *(reinterpret_cast<std::string*>(s_##name[0].s));
Original comment by [email protected]
on 8 Jan 2010 at 7:10
from gflags.
I found that changing the offending line:
std::string& FLAGS_##name = *(reinterpret_cast<std::string*>(s_##name[0].s));
to:
std::string& FLAGS_##name = *const_cast<std::string*>(FLAGS_no##name);
fixes the issue. Given below is the complete macro implementation with the fix.
#define DEFINE_string(name, val, txt) \
namespace fLS { \
static union { void* align; char s[sizeof(std::string)]; } s_##name[2]; \
const std::string* const FLAGS_no##name = new (s_##name[0].s) std::string(val); \
static ::google::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) std::string(*FLAGS_no##name)); \
extern std::string& FLAGS_##name; \
using fLS::FLAGS_##name; \
std::string& FLAGS_##name = *const_cast<std::string*>(FLAGS_no##name); \
} \
using fLS::FLAGS_##name
Original comment by [email protected]
on 8 Jan 2010 at 7:26
from gflags.
Nice fix! But I'm wondering now why we'd bother to have the const at all in
this
case. What if you changed it to this:
---
#define DEFINE_string(name, val, txt) \
namespace fLS { \
static union { void* align; char s[sizeof(std::string)]; } s_##name[2]; \
std::string* const FLAGS_no##name = new (s_##name[0].s) std::string(val); \
static ::google::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) std::string(*FLAGS_no##name)); \
extern std::string& FLAGS_##name; \
using fLS::FLAGS_##name; \
std::string& FLAGS_##name = *FLAGS_no##name; \
} \
using fLS::FLAGS_##name
---
Does that still work for you? If so, I'll make it part of the next release.
Original comment by [email protected]
on 8 Jan 2010 at 7:51
- Changed state: Accepted
from gflags.
> Does that still work for you? If so, I'll make it part of the next release.
That was actually my first fix and that does work too. The only reason I even
suggested
the other fix was because I wanted to keep the suggested changes to a minimum.
:)
Original comment by [email protected]
on 8 Jan 2010 at 7:54
from gflags.
Original comment by [email protected]
on 30 Apr 2010 at 11:28
- Changed state: Started
from gflags.
This should be fixed in gflags 1.4, just released.
Original comment by [email protected]
on 14 Oct 2010 at 1:21
- Changed state: Fixed
from gflags.
Related Issues (20)
- Add ability to have options that can be specified multiple times. HOT 2
- Please put the label 'google' on this project HOT 5
- Warnings in Visual Studio 2010 and unable to compile unit test HOT 10
- Can't locate auto/Autom4te/XFile/msg.al in @INC HOT 2
- How to set kRootDir for FlagValue::CleanName
- Support NuGet package generation for Windows users HOT 1
- @GFLAGS_IS_A_DLL@ expands to empty string in gflags_declare.h HOT 6
- Set INTERFACE_COMPILE_DEFINITIONS of imported gflags library targets to define GFLAGS_DLL_DECL HOT 2
- Google glog fails to compile against gflags HOT 5
- Google glog fails to find gflags/gflags.h when using google namespace HOT 4
- Compilation error on Windows when trying to use the library. HOT 2
- Add library versioning (soname) HOT 6
- Import symbols into google namespace to maintain backwards compatibility HOT 10
- Flags always have default value HOT 1
- Bad soname version in current git master HOT 10
- Incorrect makefile generation with cmake HOT 1
- compile problem HOT 5
- Support uint32 as flag type
- ReloadNonCommandFlags needed HOT 2
- FindThreadsCXX error when cross-compiling HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gflags.