nridge updated this revision to Diff 416827. nridge added a comment. Herald added a project: All.
Now with clang test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D113874/new/ https://reviews.llvm.org/D113874 Files: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp clang/lib/Sema/SemaTemplate.cpp clang/test/SemaTemplate/deduction-guide.cpp
Index: clang/test/SemaTemplate/deduction-guide.cpp =================================================================== --- clang/test/SemaTemplate/deduction-guide.cpp +++ clang/test/SemaTemplate/deduction-guide.cpp @@ -206,3 +206,39 @@ // CHECK: `-TemplateArgument expr // CHECK-NOT: Subst // CHECK: `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int' + +template <char = 'x'> struct F; + +template <char> struct F { + template <typename U> + requires(false) F(U); + template <typename U> + requires(true) F(U); +}; + +template <typename T> F(T) -> F<>; + +F s(0); + +// CHECK-LABEL: Dumping <deduction guide for F>: +// CHECK: FunctionTemplateDecl +// CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0 +// CHECK: `-TemplateArgument expr +// CHECK: | |-inherited from NonTypeTemplateParm {{.*}} '' 'char' +// CHECK: | `-ConstantExpr {{.*}} 'char' +// CHECK: | |-value: Int 120 +// CHECK: | `-CharacterLiteral {{.*}} 'char' 120 +// CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U +// CHECK: |-ParenExpr {{.*}} 'bool' +// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false +// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (type-parameter-0-1) -> F<>' +// CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-1' +// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<'x'>' +// CHECK: |-TemplateArgument integral 120 +// CHECK: |-TemplateArgument type 'int' +// CHECK: | `-BuiltinType {{.*}} 'int' +// CHECK: `-ParmVarDecl {{.*}} 'int':'int' +// CHECK: FunctionProtoType {{.*}} 'auto (type-parameter-0-1) -> F<>' dependent trailing_return cdecl +// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent +// CHECK: | `-CXXRecord {{.*}} 'F' +// CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 index 1 Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2184,10 +2184,24 @@ SubstArgs.push_back(SemaRef.Context.getCanonicalTemplateArgument( SemaRef.Context.getInjectedTemplateArg(NewParam))); } + + // Substitute new template parameters into requires-clause if present. + Expr *RequiresClause = nullptr; + if (Expr *InnerRC = InnerParams->getRequiresClause()) { + MultiLevelTemplateArgumentList Args; + Args.setKind(TemplateSubstitutionKind::Rewrite); + Args.addOuterTemplateArguments(SubstArgs); + Args.addOuterRetainedLevel(); + ExprResult E = SemaRef.SubstExpr(InnerRC, Args); + if (E.isInvalid()) + return nullptr; + RequiresClause = E.getAs<Expr>(); + } + TemplateParams = TemplateParameterList::Create( SemaRef.Context, InnerParams->getTemplateLoc(), InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(), - /*FIXME: RequiresClause*/ nullptr); + RequiresClause); } // If we built a new template-parameter-list, track that we need to Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -791,6 +791,27 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } +TEST(DiagnosticsTest, ConstrainedImplicitDeductionGuides) { + Annotations Header(R"cpp( +template<char = 'x'> struct S; + +template<char> struct S { + template<typename U> requires(false) S(U); + template<typename U> requires(true) S(U); +}; + +template<typename T> S(T) -> S<>; + )cpp"); + Annotations Main(R"cpp( + #include "a.h" + S s(0); + )cpp"); + TestTU TU = TestTU::withCode(Main.code()); + TU.ExtraArgs.push_back("-std=c++20"); + TU.AdditionalFiles = {{"a.h", std::string(Header.code())}}; + EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); +} + TEST(ClangdTest, MSAsm) { // Parsing MS assembly tries to use the target MCAsmInfo, which we don't link. // We used to crash here. Now clang emits a diagnostic, which we filter out.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits