[cfe-dev] Doubt about Decl::getDeclContext()

John McCall rjmccall at apple.com
Wed May 26 14:36:15 PDT 2010


On May 26, 2010, at 12:49 PM, Eli Friedman wrote:
> On Wed, May 26, 2010 at 4:55 AM, Abramo Bagnara
> <abramo.bagnara at gmail.com> wrote:
>> 
>> I've just noted that unexpectedly (at least for me) getDeclContext()
>> applied to an extern VarDecl returns the FunctionDecl instead of the
>> TranslationUnitDecl:
>> 
>> int f() {
>>  extern int a;
>> }
>> 
>> Is this expected or a symptom of a bug?
> 
> Expected; even though "a" is a global in the sense of linkage, it
> isn't actually part of the global scope.  It is only visible within
> the function "f".

I agree with Abramo that the semantic DC here should be the translation unit.
There's probably a non-trivial amount of code assuming otherwise, but that
code can be fixed.

John.



More information about the cfe-dev mailing list