Author: Haojian Wu Date: 2022-12-23T12:40:39+01:00 New Revision: 32d7aae04fdb58e65a952f281ff2f2c3f396d98f
URL: https://github.com/llvm/llvm-project/commit/32d7aae04fdb58e65a952f281ff2f2c3f396d98f DIFF: https://github.com/llvm/llvm-project/commit/32d7aae04fdb58e65a952f281ff2f2c3f396d98f.diff LOG: [clang] Fix a clang crash on invalid code in C++20 mode. This crash is a combination of recovery-expr + new SemaInit.cpp code introduced by by https://reviews.llvm.org/D129531. Differential Revision: https://reviews.llvm.org/D140587 Added: Modified: clang/lib/Sema/SemaInit.cpp clang/test/SemaCXX/recovery-expr-type.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 103986521f76e..efc3274ce7d3c 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6176,7 +6176,11 @@ void InitializationSequence::InitializeFrom(Sema &S, // constructors. For example, conversion function. if (const auto *RD = dyn_cast<CXXRecordDecl>(DestType->getAs<RecordType>()->getDecl()); - S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() && + // In general, we should call isCompleteType for RD to check its + // completeness, we don't call it here as it was already called in the + // above TryConstructorInitialization. + S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() && + RD->isAggregate() && Failed() && getFailureKind() == FK_ConstructorOverloadFailed) { // C++20 [dcl.init] 17.6.2.2: // - Otherwise, if no constructor is viable, the destination type is diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp index a5ba1ae2b8222..479039f284799 100644 --- a/clang/test/SemaCXX/recovery-expr-type.cpp +++ b/clang/test/SemaCXX/recovery-expr-type.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify + namespace test0 { struct Indestructible { @@ -171,3 +173,13 @@ void f() { S.m(1); // no crash } } + +namespace test16 { +// verify we do not crash on incomplete class type. +template<typename T, typename U> struct A; // expected-note 5{{template is declared here}} +A<int, int> foo() { // expected-error {{implicit instantiation of undefined template}} + if (1 == 1) + return A<int, int>{1}; // expected-error 2{{implicit instantiation of undefined template}} + return A<int, int>(1); // expected-error 2{{implicit instantiation of undefined template}} +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits