shafik updated this revision to Diff 505252. shafik marked 2 inline comments as done. shafik added a comment.
- Switched to using auto in two if statements - Added Release notes CHANGES SINCE LAST ACTION https://reviews.llvm.org/D142490/new/ https://reviews.llvm.org/D142490 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExprMember.cpp clang/test/SemaCXX/cxx1y-generic-lambdas.cpp clang/test/SemaCXX/statements.cpp Index: clang/test/SemaCXX/statements.cpp =================================================================== --- clang/test/SemaCXX/statements.cpp +++ clang/test/SemaCXX/statements.cpp @@ -52,3 +52,14 @@ int a = test7(1); double b = test7(2.0); } + +namespace GH48405 { +void foo() { + struct S { + int i; + int j = ({i;}); // expected-error {{invalid use of non-static data member 'i'}} + // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void'}} + // expected-warning@-2 {{use of GNU statement expression extension}} + }; +} +} Index: clang/test/SemaCXX/cxx1y-generic-lambdas.cpp =================================================================== --- clang/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ clang/test/SemaCXX/cxx1y-generic-lambdas.cpp @@ -1026,3 +1026,11 @@ void *v = x(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}} void *w = y(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}} } + +namespace GH37792 { +struct A { int x; }; + +void f() { + [](auto t) -> decltype(decltype(t)::x) { return 0; }(A()); +} +} Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -161,10 +161,13 @@ } CXXRecordDecl *contextClass; - if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) + if (auto *MD = dyn_cast<CXXMethodDecl>(DC)) contextClass = MD->getParent()->getCanonicalDecl(); - else + else if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) contextClass = cast<CXXRecordDecl>(DC); + else + return AbstractInstanceResult ? AbstractInstanceResult + : IMA_Error_StaticContext; // [class.mfct.non-static]p3: // ...is used in the body of a non-static member function of class X, Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -199,6 +199,10 @@ of `CWG2699 <https://wg21.link/CWG2699>_` being accepted by WG21. - Fix crash when parsing fold expression containing a delayed typo correction. (`#61326 <https://github.com/llvm/llvm-project/issues/61326>`_) +- Fix crash when dealing with some member accesses outside of class or member + function context. + (`#37792 <https://github.com/llvm/llvm-project/issues/37792>`_) and + (`#48405 <https://github.com/llvm/llvm-project/issues/48405>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/statements.cpp =================================================================== --- clang/test/SemaCXX/statements.cpp +++ clang/test/SemaCXX/statements.cpp @@ -52,3 +52,14 @@ int a = test7(1); double b = test7(2.0); } + +namespace GH48405 { +void foo() { + struct S { + int i; + int j = ({i;}); // expected-error {{invalid use of non-static data member 'i'}} + // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void'}} + // expected-warning@-2 {{use of GNU statement expression extension}} + }; +} +} Index: clang/test/SemaCXX/cxx1y-generic-lambdas.cpp =================================================================== --- clang/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ clang/test/SemaCXX/cxx1y-generic-lambdas.cpp @@ -1026,3 +1026,11 @@ void *v = x(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}} void *w = y(f); // expected-error {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}} } + +namespace GH37792 { +struct A { int x; }; + +void f() { + [](auto t) -> decltype(decltype(t)::x) { return 0; }(A()); +} +} Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -161,10 +161,13 @@ } CXXRecordDecl *contextClass; - if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) + if (auto *MD = dyn_cast<CXXMethodDecl>(DC)) contextClass = MD->getParent()->getCanonicalDecl(); - else + else if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) contextClass = cast<CXXRecordDecl>(DC); + else + return AbstractInstanceResult ? AbstractInstanceResult + : IMA_Error_StaticContext; // [class.mfct.non-static]p3: // ...is used in the body of a non-static member function of class X, Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -199,6 +199,10 @@ of `CWG2699 <https://wg21.link/CWG2699>_` being accepted by WG21. - Fix crash when parsing fold expression containing a delayed typo correction. (`#61326 <https://github.com/llvm/llvm-project/issues/61326>`_) +- Fix crash when dealing with some member accesses outside of class or member + function context. + (`#37792 <https://github.com/llvm/llvm-project/issues/37792>`_) and + (`#48405 <https://github.com/llvm/llvm-project/issues/48405>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits