From d9de6aa270a911e28f982c4c46a9f5c752906e5c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 26 Nov 2018 22:07:08 -0800 Subject: [PATCH] C++17 compatibility: add a non-const char* overload. C++17 adds a non-const std::basic_string::data, so non-const std::strings in the test are `char*` and the const std::strings are `const char*`. See https://en.cppreference.com/w/cpp/string/basic_string/data for details. Without adding the non-const overload, the varargs overload is preferred, leading to static_assert failures: In file included from hardware/interfaces/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp:33: In file included from hardware/interfaces/keymaster/3.0/vts/functional/authorization_set.h:20: hardware/interfaces/keymaster/3.0/vts/functional/keymaster_tags.h:257:5: error: static_assert failed "Authorization other then TagType::BOOL take exactly one parameter." static_assert(tag_type == TagType::BOOL || (sizeof...(args) == 1), ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hardware/interfaces/keymaster/3.0/vts/functional/authorization_set.h:213:19: note: in instantiation of function template specialization 'android::hardware::keymaster::V3_0::Authorization' requested here push_back(Authorization(tag, std::forward(val)...)); ^ hardware/interfaces/keymaster/3.0/vts/functional/authorization_set.h:245:9: note: in instantiation of function template specialization 'android::hardware::keymaster::V3_0::AuthorizationSet::push_back, char *, unsigned long>' requested here push_back(ttag, std::forward(value)...); ^ hardware/interfaces/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp:3426:35: note: in instantiation of function template specialization 'android::hardware::keymaster::V3_0::AuthorizationSetBuilder::Authorization, char *, unsigned long>' requested here AuthorizationSetBuilder().Authorization(TAG_ASSOCIATED_DATA, aad.data(), aad.size()); ^ Bug: http://b/111067277 Test: builds Change-Id: I3d70fb5a41db16cc9dff50364cd793e0c3510ed0 --- keymaster/3.0/vts/functional/authorization_set.h | 6 ++++++ .../4.0/support/include/keymasterV4_0/authorization_set.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/keymaster/3.0/vts/functional/authorization_set.h b/keymaster/3.0/vts/functional/authorization_set.h index 60b00e4320..0c15e686fe 100644 --- a/keymaster/3.0/vts/functional/authorization_set.h +++ b/keymaster/3.0/vts/functional/authorization_set.h @@ -261,6 +261,12 @@ class AuthorizationSetBuilder : public AuthorizationSet { return Authorization(ttag, reinterpret_cast(data), data_length); } + template + AuthorizationSetBuilder& Authorization(TypedTag ttag, char* data, + size_t data_length) { + return Authorization(ttag, reinterpret_cast(data), data_length); + } + AuthorizationSetBuilder& Authorizations(AuthorizationSet&& set); AuthorizationSetBuilder& Authorizations(const AuthorizationSet& set); diff --git a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h index a131423f6a..ff08066bc0 100644 --- a/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h +++ b/keymaster/4.0/support/include/keymasterV4_0/authorization_set.h @@ -251,6 +251,12 @@ class AuthorizationSetBuilder : public AuthorizationSet { return Authorization(ttag, reinterpret_cast(data), data_length); } + template + AuthorizationSetBuilder& Authorization(TypedTag ttag, char* data, + size_t data_length) { + return Authorization(ttag, reinterpret_cast(data), data_length); + } + AuthorizationSetBuilder& Authorizations(const AuthorizationSet& set) { for (const auto& entry : set) { push_back(entry);