[clang] 5f94c9a - [AST][RecoveryExpr] Add error-bit TemplateArgument
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 07:25:19 PDT 2020
Author: Haojian Wu
Date: 2020-06-24T16:21:35+02:00
New Revision: 5f94c9a421ec7cc7ece2bd875e010639ee0783ec
URL: https://github.com/llvm/llvm-project/commit/5f94c9a421ec7cc7ece2bd875e010639ee0783ec
DIFF: https://github.com/llvm/llvm-project/commit/5f94c9a421ec7cc7ece2bd875e010639ee0783ec.diff
LOG: [AST][RecoveryExpr] Add error-bit TemplateArgument
Summary: We are missing the error-bit somehow if the error-bit is propagated
through the code path: "error type/expr" -> "template argument" ->
"template specialization type", which will lead to crashes.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82102
Added:
Modified:
clang/include/clang/AST/DependenceFlags.h
clang/lib/AST/Type.cpp
clang/test/SemaCXX/invalid-template-base-specifier.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h
index 54e12ea47fd5..7e044865b254 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -64,6 +64,23 @@ struct TypeDependenceScope {
};
using TypeDependence = TypeDependenceScope::TypeDependence;
+struct TemplateArgumentDependenceScope {
+ enum TemplateArgumentDependence : uint8_t {
+ UnexpandedPack = 1,
+ Instantiation = 2,
+ Dependent = 4,
+
+ Error = 8,
+
+ DependentInstantiation = Dependent | Instantiation,
+ None = 0,
+ All = 15,
+ LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)
+ };
+};
+using TemplateArgumentDependence =
+ TemplateArgumentDependenceScope ::TemplateArgumentDependence;
+
#define LLVM_COMMON_DEPENDENCE(NAME) \
struct NAME##Scope { \
enum NAME : uint8_t { \
@@ -82,7 +99,6 @@ using TypeDependence = TypeDependenceScope::TypeDependence;
LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
LLVM_COMMON_DEPENDENCE(TemplateNameDependence)
-LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
#undef LLVM_COMMON_DEPENDENCE
// A combined space of all dependence concepts for all node types.
@@ -137,8 +153,9 @@ class Dependence {
Dependence(TemplateArgumentDependence D)
: V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
- translate(D, TADependence::Instantiation, Instantiation) |
- translate(D, TADependence::Dependent, Dependent)) {}
+ translate(D, TADependence::Instantiation, Instantiation) |
+ translate(D, TADependence::Dependent, Dependent) |
+ translate(D, TADependence::Error, Error)) {}
Dependence(TemplateNameDependence D)
: V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
@@ -170,7 +187,8 @@ class Dependence {
TemplateArgumentDependence templateArgument() const {
return translate(V, UnexpandedPack, TADependence::UnexpandedPack) |
translate(V, Instantiation, TADependence::Instantiation) |
- translate(V, Dependent, TADependence::Dependent);
+ translate(V, Dependent, TADependence::Dependent) |
+ translate(V, Error, TADependence::Error);
}
TemplateNameDependence templateName() const {
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index ba0d86befe1b..05962f34bbf1 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3591,7 +3591,7 @@ TemplateSpecializationType::TemplateSpecializationType(
auto *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1);
for (const TemplateArgument &Arg : Args) {
- // Update instantiation-dependent and variably-modified bits.
+ // Update instantiation-dependent, variably-modified, and error bits.
// If the canonical type exists and is non-dependent, the template
// specialization type can be non-dependent even if one of the type
// arguments is. Given:
diff --git a/clang/test/SemaCXX/invalid-template-base-specifier.cpp b/clang/test/SemaCXX/invalid-template-base-specifier.cpp
index c0f5aabae831..7a1a7f801c45 100644
--- a/clang/test/SemaCXX/invalid-template-base-specifier.cpp
+++ b/clang/test/SemaCXX/invalid-template-base-specifier.cpp
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -frecovery-ast -verify %s
-bool Foo(int *); // expected-note {{candidate function not viable}} \
- // expected-note {{candidate function not viable}}
+bool Foo(int *); // expected-note 3{{candidate function not viable}}
template <typename T>
struct Crash : decltype(Foo(T())) { // expected-error {{no matching function for call to 'Foo'}}
@@ -18,3 +17,12 @@ struct Crash2 : decltype(Alias<T>()) { // expected-note {{in instantiation of te
};
void test2() { Crash2<int>(); } // expected-note {{in instantiation of template class 'Crash2<int>' requested here}}
+
+template <typename T>
+class Base {};
+template <typename T>
+struct Crash3 : Base<decltype(Foo(T()))> { // expected-error {{no matching function for call to 'Foo'}}
+ Crash3(){};
+};
+
+void test3() { Crash3<int>(); } // expected-note {{in instantiation of template class}}
More information about the cfe-commits
mailing list