From 50fa120c87980379bf3e06c655d2ab944ebe4523 Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Mon, 22 Feb 2021 10:38:54 -0800 Subject: [PATCH] Add style guideline for `using std::foo;` (#263) Co-authored-by: Chandler Carruth --- docs/project/cpp_style_guide.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/project/cpp_style_guide.md b/docs/project/cpp_style_guide.md index 7ea3328e036d..55b5d43fe629 100644 --- a/docs/project/cpp_style_guide.md +++ b/docs/project/cpp_style_guide.md @@ -110,6 +110,14 @@ these. imprecise, are at least less confusing over the course of such refactorings. - Use the `using`-based type alias syntax instead of `typedef`. +- Don't use `using` to support unqualified lookup on `std` types; for example, + `using std::vector;`. This also applies to other short namespaces, + particularly `llvm` and `clang`. + - Writing `std::` gives clearer diagnostics and avoids any possible + ambiguity, particularly for ADL. + - An exception is made for functions like `std::swap` that are + intentionally called using ADL. This pattern should be written as + `{ using std::swap; swap(thing1, thing2); }`. - Follow the rules for initialization outlined in [Abseil's tip #88](https://abseil.io/tips/88#best-practices-for-initialization). To summarize, omitting some details from the article: