<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'>
<div>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Not sure how forward-looking you want to be with this, but I
have recently taken a look at using declarations myself with a view to the
C++0x grammar.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Putting aside the concept related bits that Doug might explain
better, the two main new constructs are alias declarations and inheriting
constructors.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>You can distinguish an alias declaration because it is *<b>not</b>*
allowed a nested-name-specifier, and the identifier will be followed by an ‘=’.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> using my_type = typename
some_template<T>::type;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Inheriting constructor declarations are only allowed inside
class (or class template) definitions, and simply name a direct base-class
twice:<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> using base::base;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The effect here, though, is not to make a name available for
name lookup but to declare a family of similar constructors directly in the
derived class.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I suspect there is little to cater for in terms of supporting
inheriting constructors in the future, but it might be useful to plan for the
alias declaration.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>AlisdairM<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> cfe-dev-bounces@cs.uiuc.edu
[mailto:cfe-dev-bounces@cs.uiuc.edu] <b>On Behalf Of </b>John Thompson<br>
<b>Sent:</b> 18 June 2009 02:56<br>
<b>To:</b> cfe-dev@cs.uiuc.edu<br>
<b>Subject:</b> [cfe-dev] using declaration questions<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Hi Doug,<o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal>I've been working on using declarations a bit over the last
week, amidst continued fire-fighting elsewhere, butI thought I'd better address
some parts of it in pieces, rather than in a big unwieldy chunk. Rather
than a patch, I'll just list relevent pieces to discuss, as I have questions
about the code. I hope it formats in a readable way here.<o:p></o:p></p>
<p class=MsoNormal><br clear=all>
<o:p></o:p></p>
<p class=MsoNormal>We'll probably want to store more location information,
e.g., the source range covering the nested-name-specifier, (e.g.,
"N::M::"), the source location of the target declaration's name, and
the source location of the "using" itself. Also, how about keeping
track of the NestedNameSpecifier used to refer to the target declaration? It's
good for pretty-printing, and will also be needed when the using directive
occurs within a template and the nested-name-specifier is dependent.<o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal>I was a litte fuzzy about the exact meaning of these, but
here's my best guess. First the new renamed UsingDecl:<o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p><span style='font-size:10.0pt;color:green'>/// UsingDecl - Represents C++
using-directive. For example:<br>
/// using someNameSpace::someIdentifier;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;color:blue'>class</span><span
style='font-size:10.0pt'> UsingDecl : <span style='color:blue'>public</span>
NamedDecl {<br>
<span style='color:green'> /// \brief The source range that
covers the nested-name-specifier<br>
/// preceding the namespace name.<br>
</span>SourceRange NestedNameRange;<br>
<span style='color:green'> /// \brief The source location of
the target declaration name.<br>
</span>SourceLocation TargetNameLocation;<br>
<span style='color:green'> /// \brief The source location of
the "using" location itself.<br>
</span>SourceLocation UsingLocation;<br>
<span style='color:green'> /// \brief Target declaration.<br>
</span>NamedDecl* TargetDecl;<br>
<span style='color:green'> /// \brief Target declaration.<br>
</span>NestedNameSpecifier* TargetNestedNameDecl;<br>
<span style='color:green'> // Had 'typename' keyword.<br>
</span><span style='color:blue'>bool</span> IsTypeName;<br>
<span style='color:green'> </span>UsingDecl(DeclContext *DC,
SourceLocation L, SourceRange NNR,<br>
<span style='color:green'>
</span>SourceLocation TargetNL, SourceLocation UL, NamedDecl* Target,<br>
<span style='color:green'>
</span>NestedNameSpecifier* TargetNNS, <span style='color:blue'>bool</span>
IsTypeNameArg)<br>
<span style='color:green'> </span>:
NamedDecl(Decl::Using, DC, L, Target->getDeclName()),<br>
<span style='color:green'>
</span>NestedNameRange(NNR), TargetNameLocation(TargetNL),<br>
<span style='color:green'>
</span>UsingLocation(UL), TargetDecl(Target),<br>
<span style='color:green'>
</span>TargetNestedNameDecl(TargetNNS), IsTypeName(IsTypeNameArg) { }<br>
<span style='color:blue'>public</span>:\<br>
<span style='color:green'> /// \brief Returns the source
range that covers the nested-name-specifier<br>
/// preceding the namespace name.<br>
</span>SourceRange getNestedNameRange() { <span
style='color:blue'>return</span>(NestedNameRange); }<br>
<span style='color:green'> /// \brief Returns the source
location of the target declaration name.<br>
</span>SourceLocation getTargetNameLocation() { <span
style='color:blue'>return</span><span style='color:green'> </span>(TargetNameLocation);
}<br>
<span style='color:green'> /// \brief Returns the source
location of the "using" location itself.<br>
</span>SourceLocation getUsingLocation() { <span
style='color:blue'>return</span>(UsingLocation); }<br>
<span style='color:green'> /// \brief getTargetDecl - Returns
target specified by using-decl.<br>
</span>NamedDecl *getTargetDecl() { <span style='color:blue'>return</span>(TargetDecl);
}<br>
<span style='color:green'> /// \brief Get target nested
name declaration.<br>
</span>NestedNameSpecifier* getTargetNestedNameDecl() { <span
style='color:blue'>return</span>(TargetNestedNameDecl); }<br>
<span style='color:green'> /// \brief isTypeName - Return
true if using decl had 'typename'.<br>
</span><span style='color:blue'>bool</span> isTypeName() <span
style='color:blue'>const</span> { <span style='color:blue'>return</span>(IsTypeName);
}<br>
<br>
<span style='color:green'> </span><span style='color:blue'>static</span>
UsingDecl *Create(ASTContext &C, DeclContext *DC,<br>
<span style='color:green'> </span>SourceLocation
L, SourceRange NNR, SourceLocation TargetNL,<br>
<span style='color:green'> </span>SourceLocation
UL, NamedDecl* Target,<br>
<span style='color:green'> </span>NestedNameSpecifier*
TargetNNS, <span style='color:blue'>bool</span> IsTypeNameArg);<br>
<br>
<span style='color:green'> </span><span
style='color:blue'>static</span> <span style='color:blue'>bool</span> classof(<span
style='color:blue'>const</span> Decl *D) {<br>
<span style='color:green'>
</span><span style='color:blue'>return</span> D->getKind() == Decl::Using;<br>
<span style='color:green'> </span>}<span
style='color:green'><br>
</span><span style='color:blue'>static</span> <span
style='color:blue'>bool</span> classof(<span style='color:blue'>const</span>
UsingDecl *D) { <span style='color:blue'>return</span> <span style='color:blue'>true</span>;
}<br>
};</span><o:p></o:p></p>
<p>Regarding the later comment:<o:p></o:p></p>
<p>Oh, and we might even consider storing the list of declarations that the
using declaration refers to, because we need to model the semantics of
paragraph 11:<o:p></o:p></p>
<p> The entity declared by a
using-declaration shall be known in the context using it according to its definition<br>
at the point of the using-declaration . Definitions added to the namespace after
the using-declaration are not<br>
considered when a use of the name is made.<o:p></o:p></p>
<p>I'm not sure what list of declarations is needed. If later definitions
appear, it seems that a look up will find the using declaration first, and
return the refered-to declaration. Or does this have something to do with
overloading?<o:p></o:p></p>
<p>The additional source locations are handled in ActOnUsingDeclaration like:<o:p></o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt'> UsingAlias
= UsingDecl::Create(Context, CurContext, IdentLoc, SS.getRange(),<br>
NS->getLocation(), UsingLoc, NS,<br>
<span style='color:blue'>static_cast</span><NestedNameSpecifier
*>(SS.getScopeRep()),<br>
IsTypeName); <o:p></o:p></span></p>
<p><span style='font-size:10.0pt'>Does this seem right?<o:p></o:p></span></p>
<p><span style='font-size:10.0pt'>Lastly, do you think Sema::LookupParsedName is
the right place to do the substitution for non-redeclaration lookups? Or
should it be lower in LookupName, with more conditions to exclude certain
lookup types?<o:p></o:p></span></p>
<p><span style='font-size:10.0pt'>I'll be experimenting with this next, as well
as writing a bigger test, to ring out some of the trickier cases.<o:p></o:p></span></p>
<p>-John<o:p></o:p></p>
<p style='margin-bottom:12.0pt'><br>
-- <br>
John Thompson<br>
<a href="mailto:John.Thompson.JTSoftware@gmail.com">John.Thompson.JTSoftware@gmail.com</a><o:p></o:p></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
</div>
</div>
</div>
</body>
</html>