diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index e2855e7..a81f6a4 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -159,7 +159,8 @@ namespace cppast exclude, //< Exclude the entire entity. exclude_return, //< Exclude the return type of a function entity. exclude_target, //< Exclude the underlying entity of an alias (e.g. typedef). - declaration, //< Only write declaration. + exclude_noexcept_condition, //< Exclude the condition of a noexcept.` + declaration, //< Only write declaration. /// For a macro, it won't show the replacement if this flag is set _flag_set_size, //< \exclude }; diff --git a/src/code_generator.cpp b/src/code_generator.cpp index 04e1391..2f1007e 100644 --- a/src/code_generator.cpp +++ b/src/code_generator.cpp @@ -500,7 +500,14 @@ namespace else { output << keyword("noexcept") << punctuation("(") << bracket_ws; - detail::write_expression(output, cond); + // update check when expression gets exposed + if (cond.kind() == cpp_expression_kind::unexposed_t + && static_cast(cond).expression() == "false") + output << keyword("false"); + else if (output.options().is_set(code_generator::exclude_noexcept_condition)) + output.excluded(base); + else + detail::write_expression(output, cond); output << bracket_ws << punctuation(")"); } } diff --git a/test/code_generator.cpp b/test/code_generator.cpp index fde5708..637471e 100644 --- a/test/code_generator.cpp +++ b/test/code_generator.cpp @@ -162,7 +162,7 @@ struct foo{ else if (e.name() == "FOO") // don't show macro replacement return code_generator::declaration; - return {}; + return code_generator::exclude_noexcept_condition; } }; @@ -174,7 +174,7 @@ void func(int a, int e, int c); #define FOO hidden template -void tfunc(int a); +void tfunc(int a) noexcept(false); struct base {}; struct e_t {}; @@ -198,13 +198,15 @@ public: private: int e3; }; + +void func2() noexcept(0 == 1 && 42); )"; auto synopsis = R"(void func(int a,int c); #define FOO -void tfunc(int a); +void tfunc(int a)noexcept(false); struct base{ }; @@ -221,6 +223,8 @@ class foo{ public: int c; }; + +void func2()noexcept(excluded); )"; auto file = parse({}, "code_generator_exclude.cpp", code);