<html>
<head>
<meta content="text/html; charset=windows-1251"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 06/26/2012 06:46 PM, John McCall
wrote:<br>
</div>
<blockquote
cite="mid:64B176A6-A81C-4864-943C-734C08F9FB3F@apple.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
<div>
<div>On Jun 26, 2012, at 9:19 AM, Vassil Vassilev wrote:</div>
<blockquote type="cite">
<div bgcolor="#FFFFFF" text="#000000"> Clang internals manual
says:<br>
"Each declaration has two potentially different
declaration contexts: a <i>lexical</i> context, which
corresponds to the source-centric view of the declaration
context, and a <i>semantic</i> context, which corresponds
to the semantics-centric view."<br>
<br>
When debugging the code snippet:<br>
enum E {e1 = -12}<br>
In the debugger I see:<br>
#1 0x00007ffff60cd4cb in clang::Sema::ActOnEnumConstant
(this=0x44e6b0, S=0x4099c0, theEnumDecl=0x4e5a70,
lastEnumConst=0x0, IdLoc=..., Id=0x46a240, Attr=0x0,
EqualLoc=..., <br>
Val=0x4e5b40) at
/home/vvassilev/workspace/llvm/src/tools/clang/lib/Sema/SemaDecl.cpp:10229<br>
10229 PushOnScopeChains(New, S);<br>
(gdb) p New<br>
$99 = (clang::EnumConstantDecl *) 0x4e5b60<br>
(gdb) p New->getDeclContext ()<br>
$100 = (clang::DeclContext *) <b>0x4e5aa8</b><br>
(gdb) p New->getLexicalDeclContext ()<br>
$101 = (clang::DeclContext *) <b>0x4e5aa8</b><br>
<br>
I would expect the lexical and the semantic DeclContext to
be different since "E" is transparent context. Could
somebody explain why is that? Is that expected?<br>
</div>
</blockquote>
</div>
<br>
<div>This is expected: the enum constant is still semantically a
member of the enum decl, even though its name is visible to
lookup in the surrounding context. Lexical DCs are designed
more for declarations that clearly don't semantically belong to
the context they appear in — for example, an out-of-line
definition of a member function in C++.</div>
<div><br>
</div>
<div>A C/C++ local extern declaration is another example of this,
although, unfortunately, we don't actually currently model them
that way.</div>
<div><br>
</div>
<div>John.</div>
</blockquote>
Thanks for the explanation! You are right it makes sense. The part
that I misunderstood is that the Scope is the TranslationUnit and
both lexical and semantic DeclContexts are the Enum itself.<br>
So the definition of "semantic context" in not from lookup
perspective, right?<br>
<br>
Vassil<br>
</body>
</html>