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 @@ -16759,6 +16759,9 @@ TInfo = Context.getTrivialTypeSourceInfo(T, Loc); } } + if (const auto *U = T->getUnqualifiedDesugaredType()) + if (U->isUndeducedType()) + D.setInvalidType(); DiagnoseFunctionSpecifiers(D.getDeclSpec()); diff --git a/clang/test/AST/ast-dump-undeduced-field.cpp b/clang/test/AST/ast-dump-undeduced-field.cpp new file mode 100644 --- /dev/null +++ b/clang/test/AST/ast-dump-undeduced-field.cpp @@ -0,0 +1,15 @@ +// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump %s | FileCheck %s + +template< class T > +struct Foo { + typedef T type; +}; + +struct Bar { + Bar(); + static constexpr auto A = ; + Foo::type baz; +}; + +// CHECK: -CXXRecordDecl {{.*}} invalid struct Bar definition +// CHECK: -FieldDecl {{.*}} invalid baz {{.*}} 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; +}