platform_system_core/base
Maciej Żenczykowski 62ae965b0a expected.h - fix bugprone-forwarding-reference-overload warnings
Fixes:
  system/core/base/include/android-base/expected.h:
  186:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload]
  195:22: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload]
  611:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload]

To quote Tom Cherry:
  I'm a bit confused at what's happening there.
  I think it's a bug in the linter itself.
  The general solution to that problem is a heavy dose of std::enable_if<>
  to hide that constructor when the 'U' parameter is the same class,
  but those constructors do have the necessarily std::enable_if<> lines.

  I think the problem is that the linter doesn't check that the macro
  _ENABLE_IF() expands into std::enable_if<>.  Let me try explicitly
  putting the std::enable_if<> instead of the macro and check if it
  goes away.

  I expanded the macro but the linter doesn't still doesn't accept
  the format of `std::enable_if_t<(condition_here)>* = nullptr`.
  It does accept `typename Enable = std::enable_if_t<(condition_here), void>`,
  which is the syntax used on their example here:
    https://clang.llvm.org/extra/clang-tidy/checks/bugprone-forwarding-reference-overload.html.

  That latter syntax doesn't work for us.
  See the Notes section on
    https://en.cppreference.com/w/cpp/types/enable_if
  as a reference for why what we're doing is correct.

Test: builds
Bug: 153035880
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I493ff19208cc104f5f176a36ec23fbcb914388f7
Merged-In: I493ff19208cc104f5f176a36ec23fbcb914388f7
2020-04-24 17:31:52 -07:00
..
include/android-base expected.h - fix bugprone-forwarding-reference-overload warnings 2020-04-24 17:31:52 -07:00
.clang-format Remove extraneous .clang-format files 2017-03-14 14:06:31 -07:00
abi_compatibility.cpp Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
Android.bp Set apex_available property 2020-04-20 16:06:02 +09:00
chrono_utils.cpp base: adb.exe build error 2018-02-05 09:33:10 -08:00
chrono_utils_test.cpp Move Timer from init to libbase 2017-07-10 09:28:24 -07:00
cmsg.cpp Revert "Revert "Add a way to turn off unique_fd's operator int."" 2019-05-06 16:18:02 -07:00
cmsg_test.cpp base: add helpers for sending/receiving file descriptors. 2019-02-13 13:21:54 -08:00
CPPLINT.cfg Don't show lint errors for rvalue references. 2015-04-02 18:38:01 -07:00
endian_test.cpp Add cross-platform <android-base/endian.h>. 2017-02-24 14:03:36 -08:00
errors_test.cpp base: add SystemErrorCodeToString() function. 2016-02-01 12:18:26 -08:00
errors_unix.cpp Add header that defines strerror() 2019-08-08 23:31:36 +00:00
errors_windows.cpp base: add SystemErrorCodeToString() function. 2016-02-01 12:18:26 -08:00
expected_test.cpp Convert system/core to Result::ok() 2020-02-06 17:04:27 +00:00
file.cpp Addressing comments in 1130236. 2019-10-02 16:48:22 -07:00
file_test.cpp Addressing comments in 1130236. 2019-10-02 16:48:22 -07:00
format_benchmark.cpp Create android-base/format.h that includes fmtlib headers 2019-06-14 14:55:27 -07:00
liblog_symbols.cpp Merge "base: dlopen/dlsym for liblog when SDK_VER <= 29" into rvc-dev 2020-03-18 00:58:01 +00:00
liblog_symbols.h liblog: correct new APIs per the API review 2020-03-16 15:31:52 -07:00
logging.cpp Remove thread safety from libbase logging / liblog 2020-04-23 10:33:03 -07:00
logging_test.cpp Move default tag from libbase to liblog 2020-01-23 08:39:31 -08:00
macros_test.cpp Add SIZEOF_MEMBER. 2018-04-11 12:29:50 -07:00
mapped_file.cpp Fix SEGV in libziparchive with malformed zip file. 2019-12-17 08:39:09 -08:00
mapped_file_test.cpp Fix SEGV in libziparchive with malformed zip file. 2019-12-17 08:39:09 -08:00
no_destructor_test.cpp base: steal Chromium's NoDestructor. 2019-12-06 13:23:05 -08:00
OWNERS Add OWNERS. 2017-12-07 13:30:03 -08:00
parsebool.cpp Expose ParseBool from libbase 2019-11-19 13:31:50 -08:00
parsebool_test.cpp Expose ParseBool from libbase 2019-11-19 13:31:50 -08:00
parsedouble_test.cpp Add ParseFloat (in parsedouble.h). 2018-08-08 18:17:21 -07:00
parseint_test.cpp Set errno for all error return cases. 2018-08-29 10:47:06 -07:00
parsenetaddress.cpp base: add network address parsing function from adb. 2016-01-21 20:03:33 -08:00
parsenetaddress_test.cpp base: add network address parsing function from adb. 2016-01-21 20:03:33 -08:00
process.cpp Add android::base::GetPids() function to return all pids 2019-07-01 13:55:46 -07:00
process_test.cpp Add android::base::GetPids() function to return all pids 2019-07-01 13:55:46 -07:00
properties.cpp base: add CachedProperty. 2020-02-28 15:20:29 -08:00
properties_test.cpp base: add CachedProperty. 2020-02-28 15:20:29 -08:00
README.md libbase: add a README.md covering the most frequent question. 2019-11-06 09:38:21 -08:00
result_test.cpp Merge "Convert system/core to Result::ok()" 2020-02-07 06:14:16 +00:00
scopeguard_test.cpp Allow android::base::ScopeGuard in STL containers 2018-03-26 13:30:09 -07:00
stringprintf.cpp Track rename of base/ to android-base/. 2015-12-04 22:00:26 -08:00
stringprintf_test.cpp Track rename of base/ to android-base/. 2015-12-04 22:00:26 -08:00
strings.cpp Add absl-like StringReplace. 2019-11-18 16:02:31 -08:00
strings_test.cpp Add absl-like StringReplace. 2019-11-18 16:02:31 -08:00
test_main.cpp Track rename of base/ to android-base/. 2015-12-04 22:00:26 -08:00
test_utils.cpp base: move TemporaryFile and TemporaryDir to android-base/file.h 2018-11-13 12:44:21 -08:00
test_utils_test.cpp Add Start/Stop/Reset to CapturedStdFd. 2018-09-04 14:29:23 -07:00
threads.cpp Move libbacktrace off cutils. 2018-07-11 13:55:07 -07:00
utf8.cpp Fix / suppress new unused warnings for mingw+clang 2017-11-29 21:37:28 -08:00
utf8_test.cpp switch to using android-base/file.h instead of android-base/test_utils.h 2018-11-14 09:35:34 -08:00

libbase

Who is this library for?

This library is a collection of convenience functions to make common tasks easier and less error-prone.

In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.

Should my routine be added?

The intention is to cover the 80% use cases, not be all things to all users.

If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.

The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".

If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.

Any other restrictions?

Unlike most Android code, code in libbase has to build for Mac and Windows too.

Code here is also expected to have good test coverage.

By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.