Author: VitaNuo Date: 2023-10-18T15:22:40+02:00 New Revision: 00f34eefe4ed04c95eb60074ddfdd64e65878be9
URL: https://github.com/llvm/llvm-project/commit/00f34eefe4ed04c95eb60074ddfdd64e65878be9 DIFF: https://github.com/llvm/llvm-project/commit/00f34eefe4ed04c95eb60074ddfdd64e65878be9.diff LOG: [clang] Bail out if the result of function template instantiation is not a function type. (#69459) Added: clang/test/SemaTemplate/function-decl-nested-type-alias.cpp Modified: clang/lib/Sema/SemaTemplateInstantiate.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 23de64080a070ca..d7d5ce19b75a965 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2662,7 +2662,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, } else { Result = Instantiator.TransformType(TLB, TL); } - if (Result.isNull()) + // When there are errors resolving types, clang may use IntTy as a fallback, + // breaking our assumption that function declarations have function types. + 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..4bca990f69046b5 --- /dev/null +++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp @@ -0,0 +1,16 @@ +// 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}} + // This is a function declaration, not a variable declaration! + // After substitution, we do not have a valid function type, and used to crash. + MyType var; +} + +void Test() { + Func<float>(); // expected-note {{in instantiation of function template specialization 'Func<float>' requested here}} +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits