[clang] ea79b3b - Revert "[Sema] `setInvalidDecl` for error deduction declaration"
Tom Weaver via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 03:45:47 PDT 2023
Author: Tom Weaver
Date: 2023-05-23T11:44:51+01:00
New Revision: ea79b3bc39700791567796faeeb63d12f49b8c50
URL: https://github.com/llvm/llvm-project/commit/ea79b3bc39700791567796faeeb63d12f49b8c50
DIFF: https://github.com/llvm/llvm-project/commit/ea79b3bc39700791567796faeeb63d12f49b8c50.diff
LOG: Revert "[Sema] `setInvalidDecl` for error deduction declaration"
This reverts commit eb5902ffc97163338bab95d2fd84a953ee76e96f.
Caused buildbot failures on:
https://lab.llvm.org/buildbot/#/builders/139/builds/41248
https://lab.llvm.org/buildbot/#/builders/216/builds/21637
Added:
Modified:
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
Removed:
clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 915c9b0cf1014..a55e969fa21c1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,8 +392,6 @@ Bug Fixes in This Version
- 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>`_)
- Fix crash when redefining a variable with an invalid type again with an
invalid type. (`#62447 <https://github.com/llvm/llvm-project/issues/62447>`_)
- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index cb38329ca73a5..e869117a8ea66 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7790,7 +7790,7 @@ class Sema final {
void CheckConversionDeclarator(Declarator &D, QualType &R,
StorageClass& SC);
Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
- bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+ void CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
StorageClass &SC);
void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 27d76db386f3e..adebfe85be45d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9199,8 +9199,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
diag::err_trailing_requires_clause_on_deduction_guide)
<< TrailingRequiresClause->getSourceRange();
- if (SemaRef.CheckDeductionGuideDeclarator(D, R, SC))
- return nullptr;
+ SemaRef.CheckDeductionGuideDeclarator(D, R, SC);
+
return CXXDeductionGuideDecl::Create(SemaRef.Context, DC, D.getBeginLoc(),
ExplicitSpecifier, NameInfo, R, TInfo,
D.getEndLoc());
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 150697302c5e1..e68afaa61ef1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11087,8 +11087,8 @@ struct BadSpecifierDiagnoser {
/// 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. Return true on invalid deduction-guide.
-bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+/// grammar.
+void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
StorageClass &SC) {
TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
@@ -11138,7 +11138,7 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
}
if (D.isInvalidType())
- return true;
+ return;
// Check the declarator is simple enough.
bool FoundFunction = false;
@@ -11151,9 +11151,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
<< D.getSourceRange();
break;
}
- if (!Chunk.Fun.hasTrailingReturnType())
- return Diag(D.getName().getBeginLoc(),
+ if (!Chunk.Fun.hasTrailingReturnType()) {
+ Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
+ break;
+ }
// Check that the return type is written as a specialization of
// the template specified as the deduction-guide's name.
@@ -11188,12 +11190,13 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
MightInstantiateToSpecialization = true;
}
- if (!AcceptableReturnType)
- return Diag(TSI->getTypeLoc().getBeginLoc(),
+ if (!AcceptableReturnType) {
+ Diag(TSI->getTypeLoc().getBeginLoc(),
diag::err_deduction_guide_bad_trailing_return_type)
<< GuidedTemplate << TSI->getType()
<< MightInstantiateToSpecialization
<< TSI->getTypeLoc().getSourceRange();
+ }
// Keep going to check that we don't have any inner declarator pieces (we
// could still have a function returning a pointer to a function).
@@ -11201,9 +11204,7 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
}
if (D.isFunctionDefinition())
- // we can still create a valid deduction guide here.
Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
- return false;
}
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index 763d983d20f61..e7428b5061c2e 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@ template <class a, class e>
concept g = f<a, e>::h;
template <class a, class e>
concept i = g<e, a>;
-template <typename> class j {
+template <typename> class j { // expected-note {{candidate template ignored}}
template <typename k>
requires requires { requires i<j, k>; }
- j();
+ j(); // expected-note {{candidate template ignored}}
};
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
}
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p3.cpp b/clang/test/CXX/temp/temp.res/temp.local/p3.cpp
index 87589e1e5bcdc..5e8a233d76d93 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p3.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p3.cpp
@@ -28,7 +28,8 @@ namespace PR6717 {
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 declaration without trailing return type}} \
+ cxx17-error{{deduction guide cannot have a function definition}}
template <typename C>
WebVector<T>& operator=(const C& other) { } // expected-error{{undeclared identifier 'T'}}
diff --git a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
index fd651ad1b1b48..2f0e948022fbf 100644
--- a/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,8 +241,9 @@ struct A1 {
};
struct A2 {
- template <typename Ty>
+ template <typename Ty> // expected-note {{non-deducible template parameter '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}}
};
diff --git a/clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp b/clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
deleted file mode 100644
index 9b7a343cedfb4..0000000000000
--- a/clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-// 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'}}
More information about the cfe-commits
mailing list