<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62473>62473</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            DeclPrinter: Missing semicolon in output of defaulted/deleted methods
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          strimo378
      </td>
    </tr>
</table>

<pre>
    The following code

```
struct Foo {
        Foo() = delete;
        ~Foo() = default;

    void x() __attribute__((alias("X")));
};
```

is printed as

```
struct Foo {
  Foo() = delete
  ~Foo() = default
 void x() __attribute__((alias("X")))
};
```

using `clang -Xclang -ast-print ...` see https://godbolt.org/z/Y45YdneMe

In `DeclPrinter::VisitDeclContext` the terminator of a FunctionDecl is decided by

```
    else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
 if (FD->isThisDeclarationADefinition())
        Terminator = nullptr;
 else
        Terminator = ";";
```

The code is wrong for FunctionDecl that are definition without having a body as written.

I suggest to change it to

```
    else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
      if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
        Terminator = nullptr;
      else
 Terminator = ";";
```

`FD->isDefaulted()` is necessary because explicitly defaulted methods have a body inside the AST.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU9v47YT_TT0ZWBBpmxZOujgrFb4_Q4LFGhQ7J4MWhxJU9CkQY6SuId-9oKyHMdBs2hzqCBQ_DMcznuPM1IhUG8RK7F5EJt6oUYenK8Cezq6bFssDk6fq8cBoXPGuGeyPbROo0hrke7mNk_ndxoG9mPL0DgHYvtwNSwb54QshCxBZDVoNMgostv6n-8NOjUafmMRWwCAJ0caXmbT_V4xezqMjPv9NFcoQypMXfldSClkOb-vrrb1rX8f-6WlACdPllGDCv8SKcDfAp3XPgB5Wf00sH-GagxRPJGnrVG2h-X3-asCLye4kCSJyFMIiDAwn4LIdkI2Qja90wdnOHG-F7L5Q8jmx3rzQ1v8dncR_m-j-xpb88tEn48Ost1vFIjj7BdnGV84nsEDAqM_klXsPLgOFDSjbZmcjaZAATS2pFHD4fwTDeKNQBMQqIPI0cgOmvrC7tnuWxVYZF_euhbZ14nEXX2h7412Fx9NvRTZVwqPA4W4QXkV9-5q7MhS7F40eqUe5ufxBiieb0djTuxfVZni_OmOqGr2MLcfKxnTMSZhJOnZO9tD5_w9fTwoBuUxXrE5aHgmHtzIMKineBMUxNwGFX0QM9rkTksIY99jYGAH7aBsj0Bx8F9pMT1vBdEO30vyP_WEuwenz9eckrmQOQi5umpYXzIM9Sclgyumefw5wUSefhRQnkYVLbYYgvJnOGCrxoCALydDLbE5X6sEajgiD06HqCBe9SMbSOOUULtfH5OFrjJdZqVaYLXKC1mm25XcLoaqWGWllGUr1-Va601RlIXCTnWd1lmxaTcLqmQqs3STrlK5kuk2KbKyKzMp16WWZVpuxTrFoyKTGPN0jLVgQSGMWOVyvc0WRh3QhOt_xFfRaHkY-yDWqaHA4baNiQ1W93UCvlGYClTAI7XOOAtkwY18GjmWB33jrbnU1Fc6FqM31buCRTyMh6R1RyGbeO78WZ68-x1bFrKZYg9CNlP4fwUAAP__jfQKGw">