adamcz updated this revision to Diff 363495. adamcz added a comment. ActOnInializerError instead of SetInvalidDecl
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D105478/new/ https://reviews.llvm.org/D105478 Files: clang/lib/Parse/ParseDeclCXX.cpp clang/test/AST/ast-dump-undeduced-expr.cpp clang/test/SemaCXX/crash-auto-36064.cpp clang/test/SemaCXX/cxx11-crashes.cpp Index: clang/test/SemaCXX/cxx11-crashes.cpp =================================================================== --- clang/test/SemaCXX/cxx11-crashes.cpp +++ 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<class T> +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<decltype(A)>::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; +} Index: clang/test/SemaCXX/crash-auto-36064.cpp =================================================================== --- clang/test/SemaCXX/crash-auto-36064.cpp +++ clang/test/SemaCXX/crash-auto-36064.cpp @@ -1,8 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -template <typename A, decltype(new A)> // expected-error{{new expression for type 'auto' requires a constructor argument}} +template <typename A, decltype(new A)> 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<decltype(c), int>); // 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]}} }; Index: clang/test/AST/ast-dump-undeduced-expr.cpp =================================================================== --- /dev/null +++ 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 Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ 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.
Index: clang/test/SemaCXX/cxx11-crashes.cpp =================================================================== --- clang/test/SemaCXX/cxx11-crashes.cpp +++ 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<class T> +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<decltype(A)>::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; +} Index: clang/test/SemaCXX/crash-auto-36064.cpp =================================================================== --- clang/test/SemaCXX/crash-auto-36064.cpp +++ clang/test/SemaCXX/crash-auto-36064.cpp @@ -1,8 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify -template <typename A, decltype(new A)> // expected-error{{new expression for type 'auto' requires a constructor argument}} +template <typename A, decltype(new A)> 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<decltype(c), int>); // 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]}} }; Index: clang/test/AST/ast-dump-undeduced-expr.cpp =================================================================== --- /dev/null +++ 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 Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits