[cfe-dev] warnings in clang
Argiris Kirtzidis
akyrtzi at gmail.com
Fri Nov 14 15:30:35 PST 2008
Mike Stump wrote:
> On Nov 14, 2008, at 2:55 PM, Argiris Kirtzidis wrote:
>> Mike Stump wrote:
>>> Here are the warnings from a recent build of clang (-r59324):
>>>
>>> DeclSerialization.cpp: In member function 'void
>>> clang::ScopedDecl::ReadInRec(llvm::Deserializer&, clang::ASTContext&)':
>>> DeclSerialization.cpp:170: warning: dereferencing type-punned
>>> pointer will break strict-aliasing rules
>>> DeclSerialization.cpp:171: warning: dereferencing type-punned
>>> pointer will break strict-aliasing rules
>>
>> I'm the one to blame for these. Care to explain more about what is
>> wrong and how to fix it ?
>
> Hum, depends upon your background. I'd assume you're new to the
> wording in the standards that says that you can only play with a type
> as the type (plus a few other obscure cases). If you change your code
> to always play with variables of type X, as type X, you can never get
> this error.
>
>> D.ReadUIntPtr(reinterpret_cast<uintptr_t&>(MDC->SemanticDC),
>> SemaDCPtrID);
>>
>> where 'MDC->SemanticDC' is a pointer (DeclContext*).
>
> reinterpret_cast<uintptr_t&>? Never use reinterpret_cast.
Here's a similar case, doesn't gcc has a problem with this ?
template <typename T>
void ReadPtr(T*& PtrRef, const SerializedPtrID& PtrID,
bool AllowBackpatch = true) {
ReadUIntPtr(reinterpret_cast<uintptr_t&>(PtrRef), PtrID,
AllowBackpatch);
}
More information about the cfe-dev
mailing list