[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGca9683651e52: [Sema] `setInvalidDecl` for error deduction 
declaration (authored by HerrCai0907).

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 -std=c++17 -fsyntax-only -verify %s
+
+template  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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ 

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524849.
HerrCai0907 added a comment.

format


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 -std=c++17 -fsyntax-only -verify %s
+
+template  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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524824.
HerrCai0907 added a comment.

add std option


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 -std=c++17 -fsyntax-only -verify %s
+
+template  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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 reopened this revision.
HerrCai0907 added a comment.
This revision is now accepted and ready to land.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

The build bot failures have been going for a while now so I've had to revert 
this until the author can address them, my apologies.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @HerrCai0907, this change is failing on the PS4 linux and PS5 Windows bot. 
Can you take a look? I'm guessing these failures are likely due to the PS4/PS5 
target defaulting to a different C/C++ standard than the rest of clang.

https://lab.llvm.org/buildbot/#/builders/139/builds/41248
https://lab.llvm.org/buildbot/#/builders/216/builds/21637


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb5902ffc971: [Sema] `setInvalidDecl` for error deduction 
declaration (authored by HerrCai0907).

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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-23 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 524582.
HerrCai0907 added a comment.

update comment


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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on invalid deduction-guide.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a request for a comment.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11196
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;

HerrCai0907 wrote:
> rsmith wrote:
> > Should we return that we had an error after this one too?
> if `D.isFunctionDefinition()`, we can still create valid deduction guide. I 
> think keeping it can avoid lots of meaningless error later.
I think it's worth leaving that as a comment in the code so folks know it's 
done on purpose and why.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-20 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

@rsmith could you review it again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-19 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-15 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-08 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-05 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 519847.
HerrCai0907 added a comment.

return Diag


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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11087,8 +11087,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 , QualType ,
+/// grammar. Return true on error.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return true;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11151,11 +11151,9 @@
   << D.getSourceRange();
   break;
 }
-if (!Chunk.Fun.hasTrailingReturnType()) {
-  Diag(D.getName().getBeginLoc(),
+if 

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-05 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11141-11145
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;

rsmith wrote:
> Can we just return immediately here? I don't see a reason to keep going -- 
> this error may well indicate that the developer didn't actually mean to 
> declare a deduction guide in the first place, so the diagnostic on a function 
> body below is likely to not be useful.
NIT: You can also just do `return Diag(...)` here and in other places. This is 
equal to `return true`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-05-04 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added a comment.

ping @rsmith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 marked 2 inline comments as done.
HerrCai0907 added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11196
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;

rsmith wrote:
> Should we return that we had an error after this one too?
if `D.isFunctionDefinition()`, we can still create valid deduction guide. I 
think keeping it can avoid lots of meaningless error later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-30 Thread Congcong Cai via Phabricator via cfe-commits
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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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& 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 
   WebVector& 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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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 , QualType ,
+/// grammar. Return true on error.
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
   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(),

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I wonder if there are any cases where the "deduction guide" is so broken that 
we shouldn't be creating a `CXXDeductionGuideDecl` at all. For example, if 
there's no trailing return type, then the declaration is syntactically invalid 
(and looks more like a constructor than a deduction guide), and it's not clear 
to me whether creating a `CXXDeductionGuideDecl` really makes sense.

In D149516#4308203 , @shafik wrote:

> I have some questions, why don't we always call 
> `CheckDeductionGuideDeclarator` when calling `CXXDeductionGuideDecl::Create`, 
> I felt like perhaps `CheckDeductionGuideDeclarator` should be rolled into 
> `CXXDeductionGuideDecl::Create` but then I noticed they are not paired up in 
> other locations.

`CXXDeductionGuideDecl::Create` is the low-level AST primitive for creating a 
`CXXDeductionGuideDecl`. The responsibility for validating the declaration and 
issuing diagnostics doesn't belong at that level, it belongs in `Sema`. The 
other callers are:

- When `Sema` creates an implicit deduction guide from a constructor. In this 
case `Sema` knows it's valid by construction.
- When `Sema` instantiates a deduction guide. In this case `Sema` knows it's 
valid because the template was.




Comment at: clang/lib/Sema/SemaDecl.cpp:9202
   << TrailingRequiresClause->getSourceRange();
-SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
+bool IsValid = SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
 

This is reversed from the normal Clang convention (where `true` indicates that 
an error was produced).



Comment at: clang/lib/Sema/SemaDecl.cpp:9204
 
-return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
+CXXDeductionGuideDecl* DGD = 
CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
  ExplicitSpecifier, NameInfo, R, TInfo,

Use `auto` here.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11141-11145
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;

Can we just return immediately here? I don't see a reason to keep going -- this 
error may well indicate that the developer didn't actually mean to declare a 
deduction guide in the first place, so the diagnostic on a function body below 
is likely to not be useful.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11196
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;

Should we return that we had an error after this one too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-29 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Thank you for the fix.

I have some questions, why don't we always call `CheckDeductionGuideDeclarator` 
when calling `CXXDeductionGuideDecl::Create`, I felt like perhaps 
`CheckDeductionGuideDeclarator` should be rolled into 
`CXXDeductionGuideDecl::Create` but then I noticed they are not paired up in 
other locations.

CC @rsmith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-29 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 518155.
HerrCai0907 added a comment.

add release note


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/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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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/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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11074,8 +11074,9 @@
 /// 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 , QualType ,
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
+  bool IsValid = true;
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
   assert(GuidedTemplateDecl && "missing template decl for deduction guide");
@@ -11124,7 +11125,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return IsValid;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11138,6 +11139,7 @@
   break;
 }
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;
@@ -11177,6 +11179,7 @@
 }
 
 if (!AcceptableReturnType) {
+  IsValid = false;
   Diag(TSI->getTypeLoc().getBeginLoc(),
diag::err_deduction_guide_bad_trailing_return_type)
   << GuidedTemplate << TSI->getType()
@@ -11191,6 +11194,7 @@
 
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;
 }
 
 //===--===//
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9199,11 +9199,13 @@
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
diag::err_trailing_requires_clause_on_deduction_guide)
   << TrailingRequiresClause->getSourceRange();
-

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-29 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62408
`setInvalidDecl` for invalid `CXXDeductionGuideDecl` to
avoid crashes during semantic analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149516

Files:
  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/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 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  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   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/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::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  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
@@ -11074,8 +11074,9 @@
 /// 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 , QualType ,
+bool Sema::CheckDeductionGuideDeclarator(Declarator , QualType ,
  StorageClass ) {
+  bool IsValid = true;
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
   assert(GuidedTemplateDecl && "missing template decl for deduction guide");
@@ -11124,7 +11125,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return IsValid;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11138,6 +11139,7 @@
   break;
 }
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;
@@ -11177,6 +11179,7 @@
 }
 
 if (!AcceptableReturnType) {
+  IsValid = false;
   Diag(TSI->getTypeLoc().getBeginLoc(),
diag::err_deduction_guide_bad_trailing_return_type)
   << GuidedTemplate << TSI->getType()
@@ -11191,6 +11194,7 @@
 
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;
 }
 
 //===--===//
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9199,11 +9199,13 @@
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),