llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: firstmoonlight <details> <summary>Changes</summary> When the type in a CXXTypeConstructExpr is incomplete, create a RecoveryExpr with an empty QualType to avoid triggering assertion in LookupTemplateName. Fixes https://github.com/llvm/llvm-project/issues/186579 --- Full diff: https://github.com/llvm/llvm-project/pull/191972.diff 3 Files Affected: - (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1) - (modified) clang/test/Modules/cxx20-10-2-ex5.cpp (+1-2) - (modified) clang/test/SemaCXX/recovery-expr-type.cpp (+12-5) ``````````diff diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index f7e005a40363c..8de0d6c026ef4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1514,7 +1514,8 @@ Sema::ActOnCXXTypeConstructExpr(ParsedType TypeRep, RParenOrBraceLoc, ListInitialization); if (Result.isInvalid()) Result = CreateRecoveryExpr(TInfo->getTypeLoc().getBeginLoc(), - RParenOrBraceLoc, exprs, Ty); + RParenOrBraceLoc, exprs, Ty->isIncompleteType() ? QualType() : Ty); + return Result; } diff --git a/clang/test/Modules/cxx20-10-2-ex5.cpp b/clang/test/Modules/cxx20-10-2-ex5.cpp index f222568072393..b14234d44e3be 100644 --- a/clang/test/Modules/cxx20-10-2-ex5.cpp +++ b/clang/test/Modules/cxx20-10-2-ex5.cpp @@ -61,6 +61,5 @@ int main() { auto f = rootFinder(2); // OK // error: A is incomplete return A{45}.value; // expected-error {{invalid use of incomplete type 'A'}} - // expected-error@-1 {{member access into incomplete type 'A'}} - // [email protected]:12 2{{forward declaration of 'A'}} + // [email protected]:12 {{forward declaration of 'A'}} } diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp index 5a42a11b82da5..fd38f453afc27 100644 --- a/clang/test/SemaCXX/recovery-expr-type.cpp +++ b/clang/test/SemaCXX/recovery-expr-type.cpp @@ -104,8 +104,7 @@ void test() { // verify the secondary diagnostic "cannot initialize" is emitted. namespace test8 { typedef int arr[]; -int v = arr(); // expected-error {{array types cannot be value-initialized}} \ - expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'arr'}} +int v = arr(); // expected-error {{array types cannot be value-initialized}} } namespace test9 { @@ -178,10 +177,18 @@ void f() { 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}} +template<typename T, typename U> struct A; // expected-note 3{{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}} + return A<int, int>{1}; // expected-error {{implicit instantiation of undefined template}} + return A<int, int>(1); // expected-error {{implicit instantiation of undefined template}} } } + +namespace test17 { +// Verify we do not crash on trailing expression with template keyword. +int a((enum b )b { } // expected-error {{ISO C++ forbids forward references to 'enum' types}} \ + // expected-error {{invalid use of incomplete type}} \ + // expected-note {{forward declaration of}} + -> template c); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/191972 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
