Skip to content

Commit d28267f

Browse files
committed
[AST][RecoveryExpr] Add error-bit to NestNameSpecifierDependence and TemplateNameDependence.
Summary: We might lose the error-bit if the error-bit goes through the code path "error type/expr" -> "error template argument" -> "nested name specifier" -> ... -> "template Specialization type" Template name also needs this, as a template can be nested into an error specifier, e.g. templateName apply in `TC<decltype(<recovery-expr>(Foo, int()))>::template apply` Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82526
1 parent 2c5ff48 commit d28267f

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

clang/include/clang/AST/DependenceFlags.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,26 @@ struct TypeDependenceScope {
6464
};
6565
using TypeDependence = TypeDependenceScope::TypeDependence;
6666

67-
struct TemplateArgumentDependenceScope {
68-
enum TemplateArgumentDependence : uint8_t {
69-
UnexpandedPack = 1,
70-
Instantiation = 2,
71-
Dependent = 4,
72-
73-
Error = 8,
74-
75-
DependentInstantiation = Dependent | Instantiation,
76-
None = 0,
77-
All = 15,
78-
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)
79-
};
80-
};
81-
using TemplateArgumentDependence =
82-
TemplateArgumentDependenceScope ::TemplateArgumentDependence;
83-
8467
#define LLVM_COMMON_DEPENDENCE(NAME) \
8568
struct NAME##Scope { \
8669
enum NAME : uint8_t { \
8770
UnexpandedPack = 1, \
8871
Instantiation = 2, \
8972
Dependent = 4, \
73+
Error = 8, \
9074
\
9175
None = 0, \
9276
DependentInstantiation = Dependent | Instantiation, \
93-
All = 7, \
77+
All = 15, \
9478
\
95-
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Dependent) \
79+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error) \
9680
}; \
9781
}; \
9882
using NAME = NAME##Scope::NAME;
9983

10084
LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
10185
LLVM_COMMON_DEPENDENCE(TemplateNameDependence)
86+
LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
10287
#undef LLVM_COMMON_DEPENDENCE
10388

10489
// A combined space of all dependence concepts for all node types.
@@ -149,7 +134,8 @@ class Dependence {
149134
Dependence(NestedNameSpecifierDependence D) :
150135
V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
151136
translate(D, NNSDependence::Instantiation, Instantiation) |
152-
translate(D, NNSDependence::Dependent, Dependent)){}
137+
translate(D, NNSDependence::Dependent, Dependent) |
138+
translate(D, NNSDependence::Error, Error)) {}
153139

154140
Dependence(TemplateArgumentDependence D)
155141
: V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
@@ -160,7 +146,8 @@ class Dependence {
160146
Dependence(TemplateNameDependence D)
161147
: V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
162148
translate(D, TNDependence::Instantiation, Instantiation) |
163-
translate(D, TNDependence::Dependent, Dependent)) {}
149+
translate(D, TNDependence::Dependent, Dependent) |
150+
translate(D, TNDependence::Error, Error)) {}
164151

165152
TypeDependence type() const {
166153
return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
@@ -181,7 +168,8 @@ class Dependence {
181168
NestedNameSpecifierDependence nestedNameSpecifier() const {
182169
return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
183170
translate(V, Instantiation, NNSDependence::Instantiation) |
184-
translate(V, Dependent, NNSDependence::Dependent);
171+
translate(V, Dependent, NNSDependence::Dependent) |
172+
translate(V, Error, NNSDependence::Error);
185173
}
186174

187175
TemplateArgumentDependence templateArgument() const {
@@ -194,7 +182,8 @@ class Dependence {
194182
TemplateNameDependence templateName() const {
195183
return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
196184
translate(V, Instantiation, TNDependence::Instantiation) |
197-
translate(V, Dependent, TNDependence::Dependent);
185+
translate(V, Dependent, TNDependence::Dependent) |
186+
translate(V, Error, TNDependence::Error);
198187
}
199188

200189
private:

clang/test/Sema/invalid-bitwidth-expr.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ auto func() {
1818
int X : func();
1919
};
2020
constexpr int sss = sizeof(Y);
21+
22+
bool Foo(int *); // expected-note {{candidate function not viable}}
23+
template <typename T>
24+
struct Base {};
25+
template <typename T>
26+
auto func() {
27+
// error-bit should be propagated from TemplateArgument to NestNameSpecifier.
28+
class Base<decltype(Foo(T()))>::type C; // expected-error {{no matching function for call to 'Foo'}}
29+
return C;
30+
}
31+
struct Z {
32+
int X : func<int>(); // expected-note {{in instantiation of function template}}
33+
};
34+
constexpr int ssss = sizeof(Z);

0 commit comments

Comments
 (0)