mizvekov created this revision. Herald added a project: All. mizvekov requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Signed-off-by: Matheus Izvekov <mizve...@gmail.com> Depends on D132816 <https://reviews.llvm.org/D132816> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134295 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExprMember.cpp clang/test/SemaCXX/cxx1z-ast-print.cpp clang/unittests/Tooling/Syntax/BuildTreeTest.cpp Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp =================================================================== --- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -2262,8 +2262,6 @@ template<typename T> static constexpr T x = 42; }; -// FIXME: `<int>` should be a child of `MemberExpression` and `;` of -// `ExpressionStatement`. This is a bug in clang, in `getSourceRange` methods. void test(S s) [[{ s.x<int>; }]] @@ -2272,18 +2270,18 @@ CompoundStatement |-'{' OpenParen |-ExpressionStatement Statement -| `-MemberExpression Expression -| |-IdExpression Object -| | `-UnqualifiedId UnqualifiedId -| | `-'s' -| |-'.' AccessToken -| `-IdExpression Member -| `-UnqualifiedId UnqualifiedId -| `-'x' -|-'<' -|-'int' -|-'>' -|-';' +| |-MemberExpression Expression +| | |-IdExpression Object +| | | `-UnqualifiedId UnqualifiedId +| | | `-'s' +| | |-'.' AccessToken +| | `-IdExpression Member +| | `-UnqualifiedId UnqualifiedId +| | |-'x' +| | |-'<' +| | |-'int' +| | `-'>' +| `-';' `-'}' CloseParen )txt"})); } Index: clang/test/SemaCXX/cxx1z-ast-print.cpp =================================================================== --- clang/test/SemaCXX/cxx1z-ast-print.cpp +++ clang/test/SemaCXX/cxx1z-ast-print.cpp @@ -4,7 +4,7 @@ template <long> static int x; // expected-note {{forward declaration of template entity is here}} template <auto> static int y; // expected-note {{forward declaration of template entity is here}} }; -// CHECK: int k = TypeSuffix().x + TypeSuffix().y; +// CHECK: int k = TypeSuffix().x<0L> + TypeSuffix().y<0L>; int k = TypeSuffix().x<0L> + TypeSuffix().y<0L>; // expected-warning {{instantiation of variable 'TypeSuffix::x<0>' required here, but no definition is available}} \ // expected-note {{add an explicit instantiation declaration to suppress this warning if 'TypeSuffix::x<0>' is explicitly instantiated in another translation unit}} \ // expected-warning {{instantiation of variable 'TypeSuffix::y<0L>' required here, but no definition is available}} \ Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -1161,10 +1161,10 @@ if (!Var->getTemplateSpecializationKind()) Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation, MemberLoc); - return BuildMemberExpr( - BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var, FoundDecl, - /*HadMultipleCandidates=*/false, MemberNameInfo, - Var->getType().getNonReferenceType(), VK_LValue, OK_Ordinary); + return BuildMemberExpr(BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var, + FoundDecl, /*HadMultipleCandidates=*/false, + MemberNameInfo, Var->getType().getNonReferenceType(), + VK_LValue, OK_Ordinary, TemplateArgs); } // We found something that we didn't expect. Complain. Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -158,6 +158,8 @@ - Fixed a crash in C++20 mode in Clang and Clangd when compile source with compilation errors. `Issue 53628 <https://github.com/llvm/llvm-project/issues/53628>`_ +- The template arguments of a variable template being accessed as a + member will now be represented in the AST. Improvements to Clang's diagnostics
Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp =================================================================== --- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -2262,8 +2262,6 @@ template<typename T> static constexpr T x = 42; }; -// FIXME: `<int>` should be a child of `MemberExpression` and `;` of -// `ExpressionStatement`. This is a bug in clang, in `getSourceRange` methods. void test(S s) [[{ s.x<int>; }]] @@ -2272,18 +2270,18 @@ CompoundStatement |-'{' OpenParen |-ExpressionStatement Statement -| `-MemberExpression Expression -| |-IdExpression Object -| | `-UnqualifiedId UnqualifiedId -| | `-'s' -| |-'.' AccessToken -| `-IdExpression Member -| `-UnqualifiedId UnqualifiedId -| `-'x' -|-'<' -|-'int' -|-'>' -|-';' +| |-MemberExpression Expression +| | |-IdExpression Object +| | | `-UnqualifiedId UnqualifiedId +| | | `-'s' +| | |-'.' AccessToken +| | `-IdExpression Member +| | `-UnqualifiedId UnqualifiedId +| | |-'x' +| | |-'<' +| | |-'int' +| | `-'>' +| `-';' `-'}' CloseParen )txt"})); } Index: clang/test/SemaCXX/cxx1z-ast-print.cpp =================================================================== --- clang/test/SemaCXX/cxx1z-ast-print.cpp +++ clang/test/SemaCXX/cxx1z-ast-print.cpp @@ -4,7 +4,7 @@ template <long> static int x; // expected-note {{forward declaration of template entity is here}} template <auto> static int y; // expected-note {{forward declaration of template entity is here}} }; -// CHECK: int k = TypeSuffix().x + TypeSuffix().y; +// CHECK: int k = TypeSuffix().x<0L> + TypeSuffix().y<0L>; int k = TypeSuffix().x<0L> + TypeSuffix().y<0L>; // expected-warning {{instantiation of variable 'TypeSuffix::x<0>' required here, but no definition is available}} \ // expected-note {{add an explicit instantiation declaration to suppress this warning if 'TypeSuffix::x<0>' is explicitly instantiated in another translation unit}} \ // expected-warning {{instantiation of variable 'TypeSuffix::y<0L>' required here, but no definition is available}} \ Index: clang/lib/Sema/SemaExprMember.cpp =================================================================== --- clang/lib/Sema/SemaExprMember.cpp +++ clang/lib/Sema/SemaExprMember.cpp @@ -1161,10 +1161,10 @@ if (!Var->getTemplateSpecializationKind()) Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation, MemberLoc); - return BuildMemberExpr( - BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var, FoundDecl, - /*HadMultipleCandidates=*/false, MemberNameInfo, - Var->getType().getNonReferenceType(), VK_LValue, OK_Ordinary); + return BuildMemberExpr(BaseExpr, IsArrow, OpLoc, &SS, TemplateKWLoc, Var, + FoundDecl, /*HadMultipleCandidates=*/false, + MemberNameInfo, Var->getType().getNonReferenceType(), + VK_LValue, OK_Ordinary, TemplateArgs); } // We found something that we didn't expect. Complain. Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -158,6 +158,8 @@ - Fixed a crash in C++20 mode in Clang and Clangd when compile source with compilation errors. `Issue 53628 <https://github.com/llvm/llvm-project/issues/53628>`_ +- The template arguments of a variable template being accessed as a + member will now be represented in the AST. Improvements to Clang's diagnostics
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits