[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    Re: [PATCH] Fix source range of destructor name
From:       Richard Smith <metafoo () gmail ! com>
Date:       2014-01-15 21:55:05
Message-ID: 6438654087761128549 () gmail297201516
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Wed Jan 15 2014 at 1:51:41 PM, Justin Bogner <mail@justinbogner.com>
wrote:

> Olivier Goffart <ogoffart@kde.org> writes:
> > From d131af55d2dc2cb6b2f7242697eb44d2e5d042da Mon Sep 17 00:00:00 2001
> > From: Olivier Goffart <ogoffart@woboq.com>
> > Date: Wed, 15 Jan 2014 19:45:12 +0100
> > Subject: [PATCH] Fix source range of the destructor name.
> >
> > The problem is that the destructor's DeclarationNameInfo do not have
> > a TypeSourceInfo because Sema::GetNameForDeclarator requires the
> > ParsedType to be a LocInfoType.
> >
> > Setting a proper TypeSourceInfo to the destructor changes the way it
> > it printed (from '~Foo' to '~struct Foo'.  Hence the change in
> > DeclarationName.cpp which also fix a bug when printing operator names.
> >
> > http://llvm.org/bugs/show_bug.cgi?id=15125
>
> Please add a test with this. Some minor comments below.
>
> > ---
> >  lib/AST/DeclarationName.cpp       | 5 ++++-
> >  lib/Sema/SemaExprCXX.cpp          | 5 ++++-
> >  unittests/AST/DeclPrinterTest.cpp | 2 +-
> >  3 files changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp
> > index e064e23..3811bbf 100644
> > --- a/lib/AST/DeclarationName.cpp
> > +++ b/lib/AST/DeclarationName.cpp
> > @@ -537,7 +537,10 @@ void DeclarationNameInfo::printName(raw_ostream
> &OS) const {
> >          OS << '~';
> >        else if (Name.getNameKind() == DeclarationName::
> CXXConversionFunctionName)
> >          OS << "operator ";
> > -      OS << TInfo->getType().getAsString();
> > +      LangOptions LO;
> > +      PrintingPolicy SubPolicy(LO);
> > +      SubPolicy.SuppressTagKeyword = true;
> > +      OS << TInfo->getType().getAsString(SubPolicy);
> >      } else
> >        OS << Name;
> >      return;
> > diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
> > index a0c123f..7e4f5f3 100644
> > --- a/lib/Sema/SemaExprCXX.cpp
> > +++ b/lib/Sema/SemaExprCXX.cpp
> > @@ -209,7 +209,8 @@ ParsedType Sema::getDestructorName(SourceLocation
> TildeLoc,
> >            Context.hasSameUnqualifiedType(T, SearchType)) {
> >          // We found our type!
> >
> > -        return ParsedType::make(T);
> > +        return CreateParsedType(T, Context.getTrivialTypeSourceInfo(T,
> > +
>  NameLoc));
>
> This reads better as
>
>         return CreateParsedType(T,
>                                 Context.getTrivialTypeSourceInfo(T,
> NameLoc));
>
> >        }
> >
> >        if (!SearchType.isNull())
> > @@ -245,6 +246,8 @@ ParsedType Sema::getDestructorName(SourceLocation
> TildeLoc,
> >                = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl()))
> {
> >            if (Spec->getSpecializedTemplate()->getCanonicalDecl() ==
> >                  Template->getCanonicalDecl())
> > +            return CreateParsedType(MemberOfType,
> > +                    Context.getTrivialTypeSourceInfo(MemberOfType,
> NameLoc));
>
> This is a strange way to indent this. According to clang-format, this
> should be:
>
>             return CreateParsedType(
>                 MemberOfType,
>                 Context.getTrivialTypeSourceInfo(MemberOfType, NameLoc));
>
> >              return ParsedType::make(MemberOfType);
> >          }
> >
> > diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/
> DeclPrinterTest.cpp
> > index 44fa742..2e335e3 100644
> > --- a/unittests/AST/DeclPrinterTest.cpp
> > +++ b/unittests/AST/DeclPrinterTest.cpp
> > @@ -558,7 +558,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) {
> >      "  operator Z();"
> >      "};",
> >      methodDecl(ofClass(hasName("A"))).bind("id"),
> > -    "Z operator struct Z()"));
> > +    "Z operator Z()"));
> >      // WRONG; Should be: "operator Z();"
> >  }
>
> Looks like the comment here needs updating.
>

The comment is still appropriate: we shouldn't be printing a return type.

[Attachment #5 (text/html)]

<div>On Wed Jan 15 2014 at 1:51:41 PM, Justin Bogner &lt;<a \
href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>&gt; \
wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"> Olivier Goffart &lt;<a href="mailto:ogoffart@kde.org" \
target="_blank">ogoffart@kde.org</a>&gt; writes:<br> &gt; From \
d131af55d2dc2cb6b2f7242697eb44<u></u>d2e5d042da Mon Sep 17 00:00:00 2001<br> &gt; \
From: Olivier Goffart &lt;<a href="mailto:ogoffart@woboq.com" \
target="_blank">ogoffart@woboq.com</a>&gt;<br> &gt; Date: Wed, 15 Jan 2014 19:45:12 \
+0100<br> &gt; Subject: [PATCH] Fix source range of the destructor name.<br>
&gt;<br>
&gt; The problem is that the destructor&#39;s DeclarationNameInfo do not have<br>
&gt; a TypeSourceInfo because Sema::GetNameForDeclarator requires the<br>
&gt; ParsedType to be a LocInfoType.<br>
&gt;<br>
&gt; Setting a proper TypeSourceInfo to the destructor changes the way it<br>
&gt; it printed (from &#39;~Foo&#39; to &#39;~struct Foo&#39;.  Hence the change \
in<br> &gt; DeclarationName.cpp which also fix a bug when printing operator \
names.<br> &gt;<br>
&gt; <a href="http://llvm.org/bugs/show_bug.cgi?id=15125" \
target="_blank">http://llvm.org/bugs/show_bug.<u></u>cgi?id=15125</a><br> <br>
Please add a test with this. Some minor comments below.<br>
<br>
&gt; ---<br>
&gt;  lib/AST/DeclarationName.cpp       | 5 ++++-<br>
&gt;  lib/Sema/SemaExprCXX.cpp          | 5 ++++-<br>
&gt;  unittests/AST/DeclPrinterTest.<u></u>cpp | 2 +-<br>
&gt;  3 files changed, 9 insertions(+), 3 deletions(-)<br>
&gt;<br>
&gt; diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp<br>
&gt; index e064e23..3811bbf 100644<br>
&gt; --- a/lib/AST/DeclarationName.cpp<br>
&gt; +++ b/lib/AST/DeclarationName.cpp<br>
&gt; @@ -537,7 +537,10 @@ void DeclarationNameInfo::<u></u>printName(raw_ostream \
&amp;OS) const {<br> &gt;          OS &lt;&lt; &#39;~&#39;;<br>
&gt;        else if (Name.getNameKind() == \
DeclarationName::<u></u>CXXConversionFunctionName)<br> &gt;          OS &lt;&lt; \
&quot;operator &quot;;<br> &gt; -      OS &lt;&lt; \
TInfo-&gt;getType().getAsString()<u></u>;<br> &gt; +      LangOptions LO;<br>
&gt; +      PrintingPolicy SubPolicy(LO);<br>
&gt; +      SubPolicy.SuppressTagKeyword = true;<br>
&gt; +      OS &lt;&lt; TInfo-&gt;getType().getAsString(<u></u>SubPolicy);<br>
&gt;      } else<br>
&gt;        OS &lt;&lt; Name;<br>
&gt;      return;<br>
&gt; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp<br>
&gt; index a0c123f..7e4f5f3 100644<br>
&gt; --- a/lib/Sema/SemaExprCXX.cpp<br>
&gt; +++ b/lib/Sema/SemaExprCXX.cpp<br>
&gt; @@ -209,7 +209,8 @@ ParsedType Sema::getDestructorName(<u></u>SourceLocation \
TildeLoc,<br> &gt;            Context.<u></u>hasSameUnqualifiedType(T, SearchType)) \
{<br> &gt;          // We found our type!<br>
&gt;<br>
&gt; -        return ParsedType::make(T);<br>
&gt; +        return CreateParsedType(T, \
Context.<u></u>getTrivialTypeSourceInfo(T,<br> &gt; +                                 \
NameLoc));<br> <br>
This reads better as<br>
<br>
        return CreateParsedType(T,<br>
                                Context.<u></u>getTrivialTypeSourceInfo(T, \
NameLoc));<br> <br>
&gt;        }<br>
&gt;<br>
&gt;        if (!SearchType.isNull())<br>
&gt; @@ -245,6 +246,8 @@ ParsedType Sema::getDestructorName(<u></u>SourceLocation \
TildeLoc,<br> &gt;                = \
dyn_cast&lt;<u></u>ClassTemplateSpecializationDec<u></u>l&gt;(Record-&gt;getDecl())) \
{<br> &gt;            if \
(Spec-&gt;getSpecializedTemplate(<u></u>)-&gt;getCanonicalDecl() ==<br> &gt;          \
Template-&gt;getCanonicalDecl())<br> &gt; +            return \
CreateParsedType(MemberOfType,<br> &gt; +                    \
Context.<u></u>getTrivialTypeSourceInfo(<u></u>MemberOfType, NameLoc));<br> <br>
This is a strange way to indent this. According to clang-format, this<br>
should be:<br>
<br>
            return CreateParsedType(<br>
                MemberOfType,<br>
                Context.<u></u>getTrivialTypeSourceInfo(<u></u>MemberOfType, \
NameLoc));<br> <br>
&gt;              return ParsedType::make(MemberOfType)<u></u>;<br>
&gt;          }<br>
&gt;<br>
&gt; diff --git a/unittests/AST/<u></u>DeclPrinterTest.cpp \
b/unittests/AST/<u></u>DeclPrinterTest.cpp<br> &gt; index 44fa742..2e335e3 100644<br>
&gt; --- a/unittests/AST/<u></u>DeclPrinterTest.cpp<br>
&gt; +++ b/unittests/AST/<u></u>DeclPrinterTest.cpp<br>
&gt; @@ -558,7 +558,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) {<br>
&gt;      &quot;  operator Z();&quot;<br>
&gt;      &quot;};&quot;,<br>
&gt;      methodDecl(ofClass(hasName(&quot;A&quot;<u></u>))).bind(&quot;id&quot;),<br>
 &gt; -    &quot;Z operator struct Z()&quot;));<br>
&gt; +    &quot;Z operator Z()&quot;));<br>
&gt;      // WRONG; Should be: &quot;operator Z();&quot;<br>
&gt;  }<br>
<br>
Looks like the comment here needs updating.<br></blockquote><div><br></div><div>The \
comment is still appropriate: we shouldn&#39;t be printing a return type. </div>



_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic