https://github.com/VitaNuo updated https://github.com/llvm/llvm-project/pull/69449
>From 27dc15e7467afa7bc4ee17a907a088e59719ca5d Mon Sep 17 00:00:00 2001 From: Viktoriia Bakalova <bakal...@google.com> Date: Wed, 18 Oct 2023 10:18:43 +0000 Subject: [PATCH 1/2] [clang] Bail out if the result of function template instantiation is not a function. --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 4 +++- .../function-decl-nested-type-alias.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaTemplate/function-decl-nested-type-alias.cpp diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 3b1731edec95237..fd4dbcd2cd80587 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2649,7 +2649,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, } else { Result = Instantiator.TransformType(TLB, TL); } - if (Result.isNull()) + // When clang goes into recovery mode, it substitutes the incorrect function + // type with a primitive (e.g., int). + if (Result.isNull() || !Result->isFunctionType()) return nullptr; return TLB.getTypeSourceInfo(Context, Result); diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp new file mode 100644 index 000000000000000..45e03b3c6ba850c --- /dev/null +++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s + +template <class A> +using Type = typename A::NestedType; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}} + +template <typename T> +void Func() { + using MyType = Type<T>(); // expected-note{{in instantiation of template type alias 'Type' requested here}} + MyType var; +} + +void Test() { + Func<float>(); // expected-note{{in instantiation of function template specialization 'Func<float>' requested here}} +} + >From a766065301f0e35d5e769c96b46bc1eba8550423 Mon Sep 17 00:00:00 2001 From: Viktoriia Bakalova <bakal...@google.com> Date: Wed, 18 Oct 2023 10:18:43 +0000 Subject: [PATCH 2/2] [clang] Bail out if the result of function template instantiation is not a function. --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index fd4dbcd2cd80587..273ab66ead6741e 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2649,8 +2649,8 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, } else { Result = Instantiator.TransformType(TLB, TL); } - // When clang goes into recovery mode, it substitutes the incorrect function - // type with a primitive (e.g., int). + // When clang goes into recovery mode, it might substitute + // the incorrect function type with a primitive (e.g., int). if (Result.isNull() || !Result->isFunctionType()) return nullptr; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits