This is an experimental patch which enables this sort of consteval metaprogramming:
consteval void inject_foo() { __inj("static const int foo = 42"); } consteval { inject_foo(); const char *barname = "bar"; __injf("static const int {} = {};", barname, "foo"); } static_assert(foo==bar);
The required AST nodes are the MetaprogramDecl [ consteval {...} ] and the StringInjectionStmt [ __injf(...)/__inj(...) ].
Metaprograms may be placed in namespace contexts as well as dependent and nondependent class and function contexts. Other contexts (parameter/argument/base specifier lists etc.) are not supported, but could be.
String injection statements must be placed in metaprograms or in consteval functions called only from within metaprograms; their content is injected into the enclosing context. See clang/test/CXX/meta/stringinj (at the bottom) for sample usages.
Setting syntax/language support aside, the underlying AST nodes could also be useful as implicitly generated nodes intended e.g. to represent preprocessor actions within the AST.
Enable the syntax via -fstring-injection.