Add constexpr specifier to read-only flag
constexpr is availble since C++11 and clang can take advantage
of it for a compile-time optimization.
If C++ version older than C++11 is used, we may need to emit
the constexpr specifier conditionally, e.g. using cpp_std specified
in .bp or wrapping it with a C macro.
Bug: 395633959
Test: atest aconfig.test
Change-Id: I826f07ade87847a8b3e188f300aff6907fcd76dd
diff --git a/tools/aconfig/aconfig/src/codegen/cpp.rs b/tools/aconfig/aconfig/src/codegen/cpp.rs
index d7d77c5..b2dae6f 100644
--- a/tools/aconfig/aconfig/src/codegen/cpp.rs
+++ b/tools/aconfig/aconfig/src/codegen/cpp.rs
@@ -237,11 +237,11 @@
return provider_->disabled_rw_in_other_namespace();
}
-inline bool enabled_fixed_ro() {
+constexpr inline bool enabled_fixed_ro() {
return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
}
-inline bool enabled_fixed_ro_exported() {
+constexpr inline bool enabled_fixed_ro_exported() {
return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO_EXPORTED;
}
@@ -549,7 +549,7 @@
return false;
}
-inline bool enabled_fixed_ro() {
+constexpr inline bool enabled_fixed_ro() {
return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
}
@@ -1103,7 +1103,7 @@
extern std::unique_ptr<flag_provider_interface> provider_;
-inline bool disabled_fixed_ro() {
+constexpr inline bool disabled_fixed_ro() {
return COM_ANDROID_ACONFIG_TEST_DISABLED_FIXED_RO;
}
@@ -1111,7 +1111,7 @@
return false;
}
-inline bool enabled_fixed_ro() {
+constexpr inline bool enabled_fixed_ro() {
return COM_ANDROID_ACONFIG_TEST_ENABLED_FIXED_RO;
}
diff --git a/tools/aconfig/aconfig/templates/cpp_exported_header.template b/tools/aconfig/aconfig/templates/cpp_exported_header.template
index 4643c97..f6f576a 100644
--- a/tools/aconfig/aconfig/templates/cpp_exported_header.template
+++ b/tools/aconfig/aconfig/templates/cpp_exported_header.template
@@ -41,6 +41,7 @@
extern std::unique_ptr<flag_provider_interface> provider_;
{{ for item in class_elements}}
+{{ if not is_test_mode }}{{ if item.is_fixed_read_only }}constexpr {{ endif }}{{ endif -}}
inline bool {item.flag_name}() \{
{{ -if is_test_mode }}
return provider_->{item.flag_name}();