HerrCai0907 updated this revision to Diff 518403.
HerrCai0907 marked an inline comment as done.
HerrCai0907 added a comment.

refactor


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149516/new/

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <class T> class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+                                 // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===================================================================
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template <typename Ty> // expected-note {{non-deducible template parameter 'Ty'}}
+  template <typename Ty>
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-                       // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
                        // expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/temp/temp.res/temp.local/p3.cpp
===================================================================
--- clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,8 +28,7 @@
 
     WebVector(const WebVector<T>& other) { } // expected-error{{undeclared identifier 'T'}} \
                                                 precxx17-error{{a type specifier is required}} \
-                                                cxx17-error{{deduction guide declaration without trailing return type}} \
-                                                cxx17-error{{deduction guide cannot have a function definition}}
+                                                cxx17-error{{deduction guide declaration without trailing return type}}
 
   template <typename C>
   WebVector<T>& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===================================================================
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f<a, e>::h;
 template <class a, class e>
 concept i = g<e, a>;
-template <typename> class j { // expected-note {{candidate template ignored}}
+template <typename> class j {
   template <typename k>
   requires requires { requires i<j, k>; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11073,8 +11073,8 @@
 /// Check the validity of a declarator that we parsed for a deduction-guide.
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
-/// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar. Return true on error.
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
                                          StorageClass &SC) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11124,7 +11124,7 @@
   }
 
   if (D.isInvalidType())
-    return;
+    return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11140,7 +11140,7 @@
     if (!Chunk.Fun.hasTrailingReturnType()) {
       Diag(D.getName().getBeginLoc(),
            diag::err_deduction_guide_no_trailing_return_type);
-      break;
+      return true;
     }
 
     // Check that the return type is written as a specialization of
@@ -11182,6 +11182,7 @@
           << GuidedTemplate << TSI->getType()
           << MightInstantiateToSpecialization
           << TSI->getTypeLoc().getSourceRange();
+      return true;
     }
 
     // Keep going to check that we don't have any inner declarator pieces (we
@@ -11191,6 +11192,7 @@
 
   if (D.isFunctionDefinition())
     Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return false;
 }
 
 //===----------------------------------------------------------------------===//
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9199,8 +9199,8 @@
       SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
                    diag::err_trailing_requires_clause_on_deduction_guide)
           << TrailingRequiresClause->getSourceRange();
-    SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
-
+    if (SemaRef.CheckDeductionGuideDeclarator(D, R, SC))
+      return nullptr;
     return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
                                          ExplicitSpecifier, NameInfo, R, TInfo,
                                          D.getEndLoc());
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -7781,7 +7781,7 @@
   void CheckConversionDeclarator(Declarator &D, QualType &R,
                                  StorageClass& SC);
   Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
-  void CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+  bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
                                      StorageClass &SC);
   void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
 
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 <https://github.com/llvm/llvm-project/issues/62296>`_)
+- Fix crash when handling initialization candidates for invalid deduction guide.
+  (`#62408 <https://github.com/llvm/llvm-project/issues/62408>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to