Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, doug.gregor, rsmith, dblaikie, courbet, 
saar.raz.
Quuxplusone added a project: clang.
Quuxplusone requested review of this revision.
Herald added a subscriber: cfe-commits.

This comes from lengthy discussion between @Quuxplusone and @ldionne over on 
D108216 <https://reviews.llvm.org/D108216>.
Right now, libc++ uses a "SCARY metaprogramming" version of `_EnableIf` that 
bypasses all of Clang's clever diagnostic stuff and produces bad diagnostics. 
My recent benchmarks ( 
https://quuxplusone.github.io/blog/2021/09/04/enable-if-benchmark/ ) have 
determined that the SCARYness is not buying us any speedup; therefore we are 
happy to drop it and go back to using the standard `std::enable_if` for all our 
SFINAE needs. //However//, we don't want to type out `typename 
std::enable_if<X>::type` all over the library; we want to use an alias 
template. And we can't use `std::enable_if_t` because we need a solution that 
works in C++11, and we do not provide `std::enable_if_t` in C++11.
Therefore, the name `_EnableIf` might persist for a while longer, but as merely 
a thin veneer over `std::enable_if` (instead of a whole other weird SCARY 
thing). Therefore, to get the good diagnostics, can we just make Clang treat 
`_EnableIf` as a synonym of `enable_if_t` from now on?

(Btw, this existing code is all sorts of broken, theoretically speaking. I 
filed https://bugs.llvm.org/show_bug.cgi?id=51696 about it last week. So if 
someone wants to use this PR as an excuse to go down the rabbit hole and fix it 
for real, that would be cool too.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109411

Files:
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3511,8 +3511,10 @@
 }
 
 /// Determine whether this alias template is "enable_if_t".
+/// libc++ sometimes uses "_EnableIf".
 static bool isEnableIfAliasTemplate(TypeAliasTemplateDecl *AliasTemplate) {
-  return AliasTemplate->getName().equals("enable_if_t");
+  return AliasTemplate->getName().equals("enable_if_t") ||
+         AliasTemplate->getName().equals("_EnableIf");
 }
 
 /// Collect all of the separable terms in the given condition, which


Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3511,8 +3511,10 @@
 }
 
 /// Determine whether this alias template is "enable_if_t".
+/// libc++ sometimes uses "_EnableIf".
 static bool isEnableIfAliasTemplate(TypeAliasTemplateDecl *AliasTemplate) {
-  return AliasTemplate->getName().equals("enable_if_t");
+  return AliasTemplate->getName().equals("enable_if_t") ||
+         AliasTemplate->getName().equals("_EnableIf");
 }
 
 /// Collect all of the separable terms in the given condition, which
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to