void Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {
E = E->IgnoreParens();
- if (!T->isPointerType() && !T->isIntegerType())
+ if (!T->isPointerType() && !T->isIntegerType() && !T->isDependentType())
return;
if (isa<UnaryOperator>(E) &&
cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf) {
auto *Op = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
if (isa<MemberExpr>(Op)) {
- auto MA = llvm::find(MisalignedMembers, MisalignedMember(Op));
+ auto *MA = llvm::find(MisalignedMembers, MisalignedMember(Op));
if (MA != MisalignedMembers.end() &&
- (T->isIntegerType() ||
+ (T->isDependentType() || T->isIntegerType() ||
(T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
Context.getTypeAlignInChars(
T->getPointeeType()) <= MA->Alignment))))
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct __attribute__((packed)) {
+ unsigned options;
+ template <typename T>
+ void getOptions() {
+ (T *)&options;
+ }
+ template <typename U>
+ void getOptions2() {
+ (U)&options;
+ }
+} s;
+
+struct __attribute__((packed)) { // expected-error {{anonymous structs and classes must be class members}}
+ unsigned options ;
+ template <typename T> getOptions() // expected-error {{a type specifier is required for all declarations}}
+ {
+ (T *) & options;
+ }
+};