@@ -314,6 +314,8 @@ void DeclAndTypeClangFunctionPrinter::printFunctionSignature(
314
314
os << " void" ;
315
315
}
316
316
os << ' )' ;
317
+ if (modifiers.isConst )
318
+ os << " const" ;
317
319
}
318
320
319
321
void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse (
@@ -470,14 +472,12 @@ void DeclAndTypeClangFunctionPrinter::printCxxMethod(
470
472
FunctionSignatureModifiers modifiers;
471
473
if (isDefinition)
472
474
modifiers.qualifierContext = typeDeclContext;
475
+ bool isMutating =
476
+ isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false ;
477
+ modifiers.isConst = !isMutating && !isConstructor;
473
478
printFunctionSignature (
474
479
FD, isConstructor ? " init" : FD->getName ().getBaseIdentifier ().get (),
475
480
resultTy, FunctionSignatureKind::CxxInlineThunk, {}, modifiers);
476
- bool isMutating = false ;
477
- if (auto *funcDecl = dyn_cast<FuncDecl>(FD))
478
- isMutating = funcDecl->isMutating ();
479
- if (!isMutating && !isConstructor)
480
- os << " const" ;
481
481
if (!isDefinition) {
482
482
os << " ;\n " ;
483
483
return ;
@@ -516,11 +516,9 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
516
516
FunctionSignatureModifiers modifiers;
517
517
if (isDefinition)
518
518
modifiers.qualifierContext = typeDeclContext;
519
+ modifiers.isConst = accessor->isGetter ();
519
520
printFunctionSignature (accessor, nameOS.str (), resultTy,
520
521
FunctionSignatureKind::CxxInlineThunk, {}, modifiers);
521
- if (accessor->isGetter ()) {
522
- os << " const" ;
523
- }
524
522
if (!isDefinition) {
525
523
os << " ;\n " ;
526
524
return ;
0 commit comments