[PATCH] D102241: [clang] p1099 4/5: using enum EnumTag

David Rector via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 22 10:45:29 PDT 2021


davrec added inline comments.


================
Comment at: clang/include/clang/AST/ASTContext.h:520-523
+  /// Like InstantiatedFromUsingDecl, but for using-enum declarations. Maps
+  /// from the instantiated using-enum to the templated decl from whence it
+  /// came.
+  llvm::DenseMap<NamedDecl *, NamedDecl *> InstantiatedFromUsingEnumDecl;
----------------
We need a detailed example in the documentation, since IIUC P1099 does not allow a using-enum-declaration to name "dependent" enums and thus is distinguished from using-declarations. Specifically the wording is:
> using-enum-declaration:
>      using elaborated-enum-specifier ;
> 1. The elaborated-enum-specifier shall not name a dependent type and the type shall have a reachable enum-specifier.
> ...
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html)

Now I'm not 100% clear on what that wording permits, but we need an example of how a UsingEnumDecl can be an instantiation.  Something like this maybe?  
```
template<unsigned N>
struct Foo {
  enum E { e = N };
};
template<unsigned N>
struct Bar : Foo<N> {
  using enum Foo<N>::E; //Allowed per P1099?
};
Bar<1>;
```

We can also clarify the types here to
```
llvm::DenseMap<UsingEnumDecl *, UsingEnumDecl *>
```
since there are no UnresolvedUsing*Decl` versions to account for, as there were with using decls.


================
Comment at: clang/include/clang/AST/ASTContext.h:906-907
 
   /// If the given using decl \p Inst is an instantiation of a
   /// (possibly unresolved) using decl from a template instantiation,
   /// return it.
----------------
```
  /// If the given using decl \p Inst is an instantiation of
  /// another (possibly unresolved) using decl, return it.
```


================
Comment at: clang/include/clang/AST/ASTContext.h:915-918
+  /// If the given using-enum decl \p Inst is an instantiation of a
+  /// (possibly unresolved) using decl from a template instantiation,
+  /// return it.
+  NamedDecl *getInstantiatedFromUsingEnumDecl(NamedDecl *Inst);
----------------
```
  /// If the given using-enum decl \p Inst is an instantiation of
  /// another using-enum decl, return it.
  UsingEnumDecl *getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst);
```


================
Comment at: clang/include/clang/AST/ASTContext.h:922
+  /// of the using enum decl \p Pattern of a class template.
+  void setInstantiatedFromUsingEnumDecl(NamedDecl *Inst, NamedDecl *Pattern);
+
----------------
`UsingEnumDecl *Inst, UsingEnumDecl *Pattern`


================
Comment at: clang/lib/AST/ASTContext.cpp:1574
 
+NamedDecl *ASTContext::getInstantiatedFromUsingEnumDecl(NamedDecl *UUD) {
+  auto Pos = InstantiatedFromUsingEnumDecl.find(UUD);
----------------
NamedDecl -> UsingEnumDecl


================
Comment at: clang/lib/AST/ASTContext.cpp:1582-1583
+
+void ASTContext::setInstantiatedFromUsingEnumDecl(NamedDecl *Inst,
+                                                  NamedDecl *Pattern) {
+  assert(isa<UsingEnumDecl>(Pattern) &&
----------------
NamedDecl -> UsingEnumDecl


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

https://reviews.llvm.org/D102241



More information about the cfe-commits mailing list