diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2989,9 +2989,11 @@ ExprResult Init = ParseCXXMemberInitializer( ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); - if (Init.isInvalid()) + if (Init.isInvalid()) { + if (ThisDecl) + Actions.ActOnUninitializedDecl(ThisDecl); SkipUntil(tok::comma, StopAtSemi | StopBeforeMatch); - else if (ThisDecl) + } else if (ThisDecl) Actions.AddInitializerToDecl(ThisDecl, Init.get(), EqualLoc.isInvalid()); } else if (ThisDecl && DS.getStorageClassSpec() == DeclSpec::SCS_static) // No initializer. diff --git a/clang/test/AST/ast-dump-undeduced-expr.cpp b/clang/test/AST/ast-dump-undeduced-expr.cpp new file mode 100644 --- /dev/null +++ b/clang/test/AST/ast-dump-undeduced-expr.cpp @@ -0,0 +1,7 @@ +// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck %s + +struct Foo { + static constexpr auto Bar = ; +}; + +// CHECK: -VarDecl {{.*}} invalid Bar 'const auto' static constexpr diff --git a/clang/test/SemaCXX/crash-auto-36064.cpp b/clang/test/SemaCXX/crash-auto-36064.cpp --- a/clang/test/SemaCXX/crash-auto-36064.cpp +++ b/clang/test/SemaCXX/crash-auto-36064.cpp @@ -1,8 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -template // expected-error{{new expression for type 'auto' requires a constructor argument}} +template struct b; struct d { static auto c = ; // expected-error{{expected expression}} + // expected-error@-1 {{declaration of variable 'c' with deduced type 'auto' requires an initializer}} + decltype(b); // expected-error{{expected '(' for function-style cast or type construction}} - // expected-note@-1{{while substituting prior template arguments into non-type template parameter [with A = auto]}} }; 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,22 @@ 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}} + // expected-error@-1 {{declaration of variable 'A' with deduced type 'const auto' requires an initializer}} + + 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; +}