diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -17498,8 +17498,13 @@ Record->setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); } - if (Record && FD->getType().isVolatileQualified()) - Record->setHasVolatileMember(true); + if (Record) { + if (FD->getType().isVolatileQualified()) + Record->setHasVolatileMember(true); + if (const auto *T = FD->getType()->getUnqualifiedDesugaredType()) + if (T->isUndeducedType()) + Record->setInvalidDecl(); + } // Keep track of the number of named members. if (FD->getIdentifier()) ++NumNamedMembers; diff --git a/clang/test/SemaCXX/cxx11-crashes.cpp b/clang/test/SemaCXX/cxx11-crashes.cpp --- a/clang/test/SemaCXX/cxx11-crashes.cpp +++ b/clang/test/SemaCXX/cxx11-crashes.cpp @@ -104,3 +104,20 @@ bool baz() { return __has_nothrow_constructor(B); } bool qux() { return __has_nothrow_copy(B); } } + +namespace undeduced_field { +template +struct Foo { + typedef T type; +}; + +struct Bar { + Bar(); + // The missing expression makes A undeduced. + static constexpr auto A = ; // expected-error {{expected expression}} + Foo::type B; // The type of B is also undeduced (wrapped in Elaborated). +}; + +// This used to crash when trying to get the layout of B. +Bar x; +}