From ccd4108e8919a49cf211008b8a4d2fb0954f64e1 Mon Sep 17 00:00:00 2001 From: Miki Rozloznik Date: Tue, 18 Jun 2024 22:27:18 +0800 Subject: [PATCH] constexpr literals --- compiler/extensions/cpp/freemarker/Constant.h.ftl | 2 +- test/language/literals/cpp/LiteralsTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/extensions/cpp/freemarker/Constant.h.ftl b/compiler/extensions/cpp/freemarker/Constant.h.ftl index 6f4f5b4e4..765e7ee22 100644 --- a/compiler/extensions/cpp/freemarker/Constant.h.ftl +++ b/compiler/extensions/cpp/freemarker/Constant.h.ftl @@ -13,7 +13,7 @@ <#if withCodeComments && docComments??> <@doc_comments docComments/> -const ${typeInfo.typeFullName} ${name} = ${value}; +constexpr ${typeInfo.typeFullName} ${name} = ${value}; <@namespace_end package.path/> <@include_guard_end package.path, name/> diff --git a/test/language/literals/cpp/LiteralsTest.cpp b/test/language/literals/cpp/LiteralsTest.cpp index c1b702cfe..217c88136 100644 --- a/test/language/literals/cpp/LiteralsTest.cpp +++ b/test/language/literals/cpp/LiteralsTest.cpp @@ -103,4 +103,11 @@ TEST(LiteralsTest, String) ASSERT_EQ("String with escaped values \x31 \x32 \063 \n \t \f \r \\ \""_sv, STRING); } +TEST(LiteralsTest, constexprLiteral) +{ + static_assert(BINARY_POSITIVE == 0xff, "BINARY_POSITIVE fail"); + static_assert(DECIMAL_NEGATIVE == -255, "DECIMAL_NEGATIVE fail"); + static_assert(STRING.size() == 44, "STRING fail"); +} + } // namespace literals