`auto` is now slightly more permissive (for type aliases)

Skip to first unread message


Feb 8, 2024, 4:50:36 PMFeb 8
to chromium-dev
Hi chromiumies,

As you know we have a clang extension that prevents writing `auto` when it deduces to a pointer. This was done around the C++11 transition, in order to allow use of auto, primarily because we have lots of Create() functions that sometimes return an owning pointer and sometimes a smart pointer.

However the clang extension would also look through typedefs, so if your container iterator type happens to be a pointer, it would not let you write `auto` to refer to the iterators. You would have to write `auto*`. Including for types in libc++ like std::string_view. This is non-portable code as iterators are not specified to be native pointers, and became an acute problem when we wanted to introduce hardened iterators in libc++.

So the `auto` extension is now more permissive and does not snoop through type aliases. The pointer inside the alias is considered an implementation detail.

Concretely, before we had to write:
auto* it = std::string_view().begin();
After, we can and should now write:
auto it = std::string_view().begin();


p.s. I guess, don't go around writing type aliases for owning native pointers. :)
Reply all
Reply to author
0 new messages