[LLVMbugs] [Bug 8669] New: friend decls get put in the wrong DeclContext in certain situations

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Nov 22 20:12:23 PST 2010


http://llvm.org/bugs/show_bug.cgi?id=8669

           Summary: friend decls get put in the wrong DeclContext in
                    certain situations
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: csilvers2000 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Consider the following code:
---
1 struct B {
2   template<class T> class C;
3   template<class T> friend class C;
4   //friend class C<float>;
5 };
6
7 template<class T> class C { };
8
9 C<int>* foo;
---
The declaration at line 7 and the declarations and line 2 and 3 are put in
separate DeclContexts (as far as I can tell).  To see this, when looking at the
CXXRecord for C<int> on line 9, and looking at the redecls (via
redecl_begin()/end()), the only redecl it shows is for line 7.

However, if I uncomment line 4, the situation changes.  Now if I look at the
redecls for C<float> on line 4, I see line 2, line 3, and line 7.  All 3 of
these have the same DeclContext (that is, record_decl->getParent() produces the
same output in each case), which is the DeclContext for this translation unit.

Likewise, if I look at the redecls for C<int> on line 9, I see all three decls,
on lines 2, 3, and 7.  They still all have the same DeclContext. :-)

I would not expect uncommenting line 4 to change whether lines 2 and 3 are
redecls of line 7 or not.  Nor would I expect, in any case, that the decls on
line 2 and 3 should be in the global (translation-unit) DeclContext, rather
than a DeclContext for class B.

It seems to me that the behavior when line 4 is commented is correct, but the
behavior when it is uncommented is incorrect, and clang is conflating two
DeclContexts that it shouldn't be.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list