adamcz updated this revision to Diff 357511. adamcz added a comment. Fix a more generic case of invalid static initializer
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/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,20 @@ 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}} + 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/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 @@ -2982,9 +2982,11 @@ ExprResult Init = ParseCXXMemberInitializer( ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); - if (Init.isInvalid()) + if (Init.isInvalid()) { + if (ThisDecl) + ThisDecl->setInvalidDecl(); 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,20 @@ 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}} + 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/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 @@ -2982,9 +2982,11 @@ ExprResult Init = ParseCXXMemberInitializer( ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); - if (Init.isInvalid()) + if (Init.isInvalid()) { + if (ThisDecl) + ThisDecl->setInvalidDecl(); 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