[PATCH] D80475: [TargetLoweringObjectFileImpl] Use llvm::transform

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 18:39:29 PDT 2020


MaskRay added a comment.

In D80475#2052429 <https://reviews.llvm.org/D80475#2052429>, @orivej wrote:

> My C++ library does not allow even this:


Can you double check?? The code below even works with clang 3.4 and GCC 4.7, which are both very old (lower than LLVM's build requirement).
Probably not libstdc++ or libc++.. Sigh

>   #include <algorithm>
>   #include <string>
>   
>   int main() {
>       std::string s("hello");
>       transform(s.begin(), s.end(), s.begin(), [](char c) -> char { return c; });
>   }
> 
> 
>   main.cpp:7:5: error: use of undeclared identifier 'transform'; did you mean 'std::transform'?
>       transform(s.begin(), s.end(), s.begin(), [](char c) -> char { return c; });
>       ^~~~~~~~~
>       std::transform





================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1749
   std::string HexString = AI.toString(16, /*Signed=*/false);
-  transform(HexString.begin(), HexString.end(), HexString.begin(), tolower);
+  transform(HexString, HexString.begin(), tolower);
   unsigned Size = HexString.size();
----------------
orivej wrote:
> MaskRay wrote:
> > Use `llvm::transform` to avoid future ADL gotcha.
> Are you sure? Changing the signature like this makes the name resolution argument independent, since `llvm::transform` is in scope due to `using namespace llvm;`.  Nothing else in this file qualifies `llvm::`.
We prefer a qualified name. This is similar to `llvm::sort`. Unqualified name lookups can cause ADL. STLExtras.h defines names the same as in std::. A misuse may easily pick up an unintended overload in std::


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80475





More information about the llvm-commits mailing list