llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Aditi Medhane (AditiRM) <details> <summary>Changes</summary> Pre-commit test documenting the current crash behaviour when handling explicit template specialization after instantiation. The compiler currently crashes with an assertion failure in `getASTRecordLayout()` when attempting to get layout information for an invalid declaration during error recovery. This test documents this behavior before the fix. --- Full diff: https://github.com/llvm/llvm-project/pull/208151.diff 1 Files Affected: - (added) clang/test/SemaCXX/explicit-specialization-after-instantiation-crash.cpp (+40) ``````````diff diff --git a/clang/test/SemaCXX/explicit-specialization-after-instantiation-crash.cpp b/clang/test/SemaCXX/explicit-specialization-after-instantiation-crash.cpp new file mode 100644 index 0000000000000..9120fa45330b8 --- /dev/null +++ b/clang/test/SemaCXX/explicit-specialization-after-instantiation-crash.cpp @@ -0,0 +1,40 @@ +// Test that explicit template specialization after instantiation +// is handled gracefully without assertion failure. +// +// RUN: not --crash %clang_cc1 -fsyntax-only -verify %s 2>&1 | FileCheck %s +// +// REQUIRES: asserts + +// This test case triggers an assertion failure in getASTRecordLayout() +// when the compiler encounters explicit specialization after instantiation +// and attempts to get layout information during error recovery. + +template <typename T> +struct X { + struct Y { + Y() : v(0) {} + int v; + int getValue(); + } y; +}; + +template <typename T> +int X<T>::Y::getValue() { + return ++v; +} + +// expected-error@+1 {{explicit specialization of 'Y' after instantiation}} +template <> struct X<int>::Y { int getValue() { return 55; } }; +// expected-note@-11 {{implicit instantiation first required here}} + +extern template class X<int>::Y; + +int main() { + X<int> x; + return x.y.getValue(); // expected-error {{no member named 'getValue'}} +} + +// Verify the assertion failure occurs +// CHECK: Assertion +// CHECK: isInvalidDecl +// CHECK: Cannot get layout of invalid decl \ No newline at end of file `````````` </details> https://github.com/llvm/llvm-project/pull/208151 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
