Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to merge templated static member variables #26553

Closed
vgvassilev opened this issue Jan 17, 2016 · 1 comment
Closed

Fails to merge templated static member variables #26553

vgvassilev opened this issue Jan 17, 2016 · 1 comment
Labels
bugzilla Issues migrated from bugzilla clang:modules C++20 modules and Clang Header Modules

Comments

@vgvassilev
Copy link
Contributor

Bugzilla Link 26179
Resolution FIXED
Resolved on Jan 24, 2016 16:26
Version trunk
OS All
Attachments Reproducer
CC @DougGregor,@zygoloid,@vgvassilev

Extended Description

My diagnosis is:
template struct basic_string {
static T _S_empty_rep_storage[]; // #​1
};
template T basic_string::_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' 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.
@vgvassilev
Copy link
Contributor Author

Fixed in r258524.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

1 participant