Skip to content

Commit aa0a8e9

Browse files
committed
Also move friend function definitions to top-level scope if...
they don't have an implementation. Often the friend definitions are the only definition there is, and we translate these definitions (currently always operators) to wrapper members then.
1 parent ba22737 commit aa0a8e9

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

generator/parser/binder.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_
292292
applyStorageSpecifiers(node->storage_specifiers, fun.staticCast<_MemberModelItem>());
293293
applyFunctionSpecifiers(node->function_specifiers, fun);
294294

295+
if (hasFriendSpecifier(node->storage_specifiers))
296+
{
297+
// check if this function declaration is a "friend" function.
298+
// In this case we modify the scope, and remove the "friend" flag.
299+
// This is for functions/operators that are only defined as friend
300+
// inside of classes.
301+
symbolScope = _M_current_file.staticCast<_ScopeModelItem>();
302+
// unset the friend flag, as we treat this like a stand-alone function definition
303+
fun->setFriend(false);
304+
// also set the access policy to public, just in case
305+
fun->setAccessPolicy(CodeModel::Public);
306+
}
307+
295308
if (const ListNode<InitDeclaratorAST*> *it = node->init_declarators)
296309
{
297310
it = it->toFront();
@@ -367,9 +380,9 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
367380
ScopeModelItem scope = currentScope();
368381
bool friendWithDefinition = false;
369382

370-
if (hasFriendSpecifier(node->storage_specifiers) && ast_cast<FunctionDefinitionAST*>(node))
383+
if (hasFriendSpecifier(node->storage_specifiers))
371384
{
372-
// check if this function declaration is a "friend" function with implementation body.
385+
// check if this function declaration is a "friend" function.
373386
// In this case we modify the scope, and remove the "friend" flag later on.
374387
friendWithDefinition = true;
375388
scope = _M_current_file.staticCast<_ScopeModelItem>();

0 commit comments

Comments
 (0)