[clang] d28267f - [AST][RecoveryExpr] Add error-bit to NestNameSpecifierDependence and TemplateNameDependence.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 30 03:07:30 PDT 2020


Author: Haojian Wu
Date: 2020-06-30T11:56:24+02:00
New Revision: d28267f9810ce8642b27279b91a3a195ba932ce2

URL: https://github.com/llvm/llvm-project/commit/d28267f9810ce8642b27279b91a3a195ba932ce2
DIFF: https://github.com/llvm/llvm-project/commit/d28267f9810ce8642b27279b91a3a195ba932ce2.diff

LOG: [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

Added: 
    

Modified: 
    clang/include/clang/AST/DependenceFlags.h
    clang/test/Sema/invalid-bitwidth-expr.mm

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h
index 7e044865b254..3601cb90bb76 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -64,41 +64,26 @@ 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 {                                                      \
       UnexpandedPack = 1,                                                      \
       Instantiation = 2,                                                       \
       Dependent = 4,                                                           \
+      Error = 8,                                                               \
                                                                                \
       None = 0,                                                                \
       DependentInstantiation = Dependent | Instantiation,                      \
-      All = 7,                                                                 \
+      All = 15,                                                                \
                                                                                \
-      LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Dependent)                    \
+      LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)                        \
     };                                                                         \
   };                                                                           \
   using NAME = NAME##Scope::NAME;
 
 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.
@@ -149,7 +134,8 @@ class Dependence {
   Dependence(NestedNameSpecifierDependence D) :
     V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
             translate(D, NNSDependence::Instantiation, Instantiation) |
-            translate(D, NNSDependence::Dependent, Dependent)){}
+            translate(D, NNSDependence::Dependent, Dependent) |
+            translate(D, NNSDependence::Error, Error)) {}
 
   Dependence(TemplateArgumentDependence D)
       : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
@@ -160,7 +146,8 @@ class Dependence {
   Dependence(TemplateNameDependence D)
       : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
              translate(D, TNDependence::Instantiation, Instantiation) |
-             translate(D, TNDependence::Dependent, Dependent)) {}
+             translate(D, TNDependence::Dependent, Dependent) |
+             translate(D, TNDependence::Error, Error)) {}
 
   TypeDependence type() const {
     return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
@@ -181,7 +168,8 @@ class Dependence {
   NestedNameSpecifierDependence nestedNameSpecifier() const {
     return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
            translate(V, Instantiation, NNSDependence::Instantiation) |
-           translate(V, Dependent, NNSDependence::Dependent);
+           translate(V, Dependent, NNSDependence::Dependent) |
+           translate(V, Error, NNSDependence::Error);
   }
 
   TemplateArgumentDependence templateArgument() const {
@@ -194,7 +182,8 @@ class Dependence {
   TemplateNameDependence templateName() const {
     return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
            translate(V, Instantiation, TNDependence::Instantiation) |
-           translate(V, Dependent, TNDependence::Dependent);
+           translate(V, Dependent, TNDependence::Dependent) |
+           translate(V, Error, TNDependence::Error);
   }
 
 private:

diff  --git a/clang/test/Sema/invalid-bitwidth-expr.mm b/clang/test/Sema/invalid-bitwidth-expr.mm
index 63aced1a3bf4..a38ebbbd6755 100644
--- a/clang/test/Sema/invalid-bitwidth-expr.mm
+++ b/clang/test/Sema/invalid-bitwidth-expr.mm
@@ -18,3 +18,17 @@ auto func() {
   int X : func();
 };
 constexpr int sss = sizeof(Y);
+
+bool Foo(int *); // expected-note {{candidate function not viable}}
+template <typename T>
+struct Base {};
+template <typename T>
+auto func() {
+  // error-bit should be propagated from TemplateArgument to NestNameSpecifier.
+  class Base<decltype(Foo(T()))>::type C; // expected-error {{no matching function for call to 'Foo'}}
+  return C;
+}
+struct Z {
+  int X : func<int>(); // expected-note {{in instantiation of function template}}
+};
+constexpr int ssss = sizeof(Z);


        


More information about the cfe-commits mailing list