From 1c04a24059a9b8e20058e1c4e4d86a1f560d33a8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 26 Sep 2023 08:17:55 +0200 Subject: Recognize C++11 and C++20 keywords for identifier escaping --- xsd/xsd/cxx/elements.cxx | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/xsd/xsd/cxx/elements.cxx b/xsd/xsd/cxx/elements.cxx index e914f9d..02a768e 100644 --- a/xsd/xsd/cxx/elements.cxx +++ b/xsd/xsd/cxx/elements.cxx @@ -102,6 +102,36 @@ namespace CXX L"xor", L"xor_eq" }; + + // Note: excluding "identifiers with special meaning" in certain contexts + // ("final", "override") since they shouldn't cause any issues. + // + wchar_t const* keywords_cxx11[] = { + L"alignas", + L"alignof", + L"char16_t", + L"char32_t", + L"constexpr", + L"decltype", + L"noexcept", + L"nullptr", + L"static_assert", + L"thread_local" + }; + + // Note: excluding "identifiers with special meaning" in certain contexts + // ("import", "module") since they shouldn't cause any issues. + // + wchar_t const* keywords_cxx20[] = { + L"char8_t", + L"concept", + L"consteval", + L"constinit", + L"co_await", + L"co_return", + L"co_yield", + L"requires" + }; } // Context @@ -268,8 +298,21 @@ namespace CXX // Populate the keyword set. // - for (size_t i (0); i < sizeof (keywords) / sizeof (char*); ++i) + for (size_t i (0); i < sizeof (keywords) / sizeof (wchar_t*); ++i) keyword_set_.insert (keywords[i]); + + if (std >= cxx_version::cxx11) + { + for (size_t i (0); i < sizeof (keywords_cxx11) / sizeof (wchar_t*); ++i) + keyword_set_.insert (keywords_cxx11[i]); + } + + if (std >= cxx_version::cxx20) + { + for (size_t i (0); i < sizeof (keywords_cxx20) / sizeof (wchar_t*); ++i) + keyword_set_.insert (keywords_cxx20[i]); + } + } String Context:: -- cgit v1.1