[llvm-bugs] [Bug 26179] New: Fails to merge templated static member variables

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jan 16 14:35:53 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26179

            Bug ID: 26179
           Summary: Fails to merge templated static member variables
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Modules
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vvasilev at cern.ch
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

My diagnosis is:
template<typename T> struct basic_string {
  static T _S_empty_rep_storage[]; // #1
};
template<typename T> T basic_string<T>::_S_empty_rep_storage[sizeof(T)]; // #2

#1 and #2 end up on the same redecl chain. #2 gets registered in the lookup
table and when isSameEntity compares the type of the imported VarDecl
(essentially #1 coming from another module) it finds a mismatch.

A fix to this issue is just dialing Existing->getCanonicalDecl. There are two
questions I cannot answer (yet?):
  1. Should #2 really end up in the redecl chain, it looks like a different
decl (at least when it comes to types, true that both are
IncompleteArrayTypes]?
  2. Why #2 ended up in the lookup table when #1 was seen before?
    3. Where should the fix go:
      a) should it be isSameEntity(Existing->getCanonicalDecl(), D) -
semantically #2 cannot end up as a canonical decl.
      b) should I extend the logic (somehow) of isSameEntity (VarDecl section)?




   2872        DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
   2873        for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I
!= E; ++I) {
   2874          if (NamedDecl *Existing = getDeclForMerging(*I,
TypedefNameForLinkage))
-> 2875            if (isSameEntity(Existing, D))
   2876              return FindExistingResult(Reader, D, Existing,
AnonymousDeclNumber,
   2877                                        TypedefNameForLinkage);
   2878        }
(lldb) p Existing
(clang::VarDecl *) $186 = 0x000000010c831390
(lldb) p Existing->dump()
VarDecl 0x10c831390 parent 0x10c051530 prev 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:9:1,
line:10:50> col:20 _S_empty_rep_storage 'T [sizeof(T)]'
(lldb) p Existing->getPreviousDecl()
(clang::VarDecl *) $187 = 0x000000010c830fa8
(lldb) p Existing->getPreviousDecl()->dump()
VarDecl 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:3,
col:33> col:12 _S_empty_rep_storage 'T []' static
(lldb) p Existing->getPreviousDecl()->getPreviousDecl()
(clang::Decl *) $188 = 0x0000000000000000
(lldb) p Existing->getMostRecentDecl()
(clang::VarDecl *) $189 = 0x000000010c831390
(lldb) p Existing->getCanonicalDecl()
(clang::VarDecl *) $190 = 0x000000010c830fa8
(lldb) p Existing->getCanonicalDecl()->dump()
VarDecl 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:3,
col:33> col:12 _S_empty_rep_storage 'T []' static

The error message is:

In module 'B' imported from
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/A.h:5:
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:12:
error: 'basic_string::_S_empty_rep_storage' from module 'B' is not present in
definition of 'basic_string<T>' provided earlier
  static T _S_empty_rep_storage[];
           ^
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:12:
note: declaration of '_S_empty_rep_storage' does not match
  static T _S_empty_rep_storage[];
           ^
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/prN.cpp:5:10:
fatal error: could not build module 'A'
#include "A.h"
 ~~~~~~~~^~~~~
2 errors generated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160116/141ff516/attachment.html>


More information about the llvm-bugs mailing list