new warnings n -r61596

DeclCXX.cpp: In member function 'clang::Decl** clang::LinkageSpecDecl::decls_begin() const':
DeclCXX.cpp:326: warning: dereferencing type-punned pointer will break strict-aliasing rules
DeclCXX.cpp: In member function 'clang::Decl** clang::LinkageSpecDecl::decls_end() const':
DeclCXX.cpp:331: warning: dereferencing type-punned pointer will break strict-aliasing rules

Thanks, Mike, but I'm a bit confused: I've turned on -Wstrict-aliasing and I don't see this warning, so I don't know how to suppress it. I believe that the code itself is correct (the void* decl is either handled as a Decl* or as a Decl**, depending on the HadBraces bit).

  - Doug

Douglas Gregor wrote:

DeclCXX.cpp: In member function 'clang::Decl**
clang::LinkageSpecDecl::decls_begin() const':
DeclCXX.cpp:326: warning: dereferencing type-punned pointer will break
strict-aliasing rules
DeclCXX.cpp: In member function 'clang::Decl**
clang::LinkageSpecDecl::decls_end() const':
DeclCXX.cpp:331: warning: dereferencing type-punned pointer will break
strict-aliasing rules

Thanks, Mike, but I'm a bit confused: I've turned on -Wstrict-aliasing
and I don't see this warning, so I don't know how to suppress it.

I think you have to turn on optimizations for this warning to work.
(Sucks, but that's the way gcc works...)

I believe that the code itself is correct (the void* decl is either
handled as a Decl* or as a Decl**, depending on the HadBraces bit).

Not that it really matters anymore, since the code in question is
gone, but the code is wrong... the issue boils down to a testcase like
the following:

class Decl;
void* Decls;
Decl** x() {return (Decl**)&Decls;}
Decl* y() {return *x();}

Calling y() results in undefined behavior because the Decl** points to
a void*, and Decl* and void* aren't allowed to alias. One correct
solution is using a declaration like "union {Decl **declArrayPtr,
*declPtr} Decls;" instead of "void *Decls;".

-Eli