{"action":"created","issue":{"url":"https://api.github.com/repos/Ericsson/clang/issues/386","repository_url":"https://api.github.com/repos/Ericsson/clang","labels_url":"https://api.github.com/repos/Ericsson/clang/issues/386/labels{/name}","comments_url":"https://api.github.com/repos/Ericsson/clang/issues/386/comments","events_url":"https://api.github.com/repos/Ericsson/clang/issues/386/events","html_url":"https://github.com/Ericsson/clang/pull/386","id":321266457,"number":386,"title":"Fix duplicate class template definitions problem","user":{"login":"martong","id":5887427,"avatar_url":"https://avatars0.githubusercontent.com/u/5887427?v=4","gravatar_id":"","url":"https://api.github.com/users/martong","html_url":"https://github.com/martong","followers_url":"https://api.github.com/users/martong/followers","following_url":"https://api.github.com/users/martong/following{/other_user}","gists_url":"https://api.github.com/users/martong/gists{/gist_id}","starred_url":"https://api.github.com/users/martong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martong/subscriptions","organizations_url":"https://api.github.com/users/martong/orgs","repos_url":"https://api.github.com/users/martong/repos","events_url":"https://api.github.com/users/martong/events{/privacy}","received_events_url":"https://api.github.com/users/martong/received_events","type":"User","site_admin":false},"labels":[{"id":814013038,"url":"https://api.github.com/repos/Ericsson/clang/labels/ASTImporter","name":"ASTImporter","color":"f0f477","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-08T16:55:33Z","updated_at":"2018-05-11T13:11:14Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/Ericsson/clang/pulls/386","html_url":"https://github.com/Ericsson/clang/pull/386","diff_url":"https://github.com/Ericsson/clang/pull/386.diff","patch_url":"https://github.com/Ericsson/clang/pull/386.patch"},"body":""},"comment":{"url":"https://api.github.com/repos/Ericsson/clang/issues/comments/388359029","html_url":"https://github.com/Ericsson/clang/pull/386#issuecomment-388359029","issue_url":"https://api.github.com/repos/Ericsson/clang/issues/386","id":388359029,"user":{"login":"martong","id":5887427,"avatar_url":"https://avatars0.githubusercontent.com/u/5887427?v=4","gravatar_id":"","url":"https://api.github.com/users/martong","html_url":"https://github.com/martong","followers_url":"https://api.github.com/users/martong/followers","following_url":"https://api.github.com/users/martong/following{/other_user}","gists_url":"https://api.github.com/users/martong/gists{/gist_id}","starred_url":"https://api.github.com/users/martong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martong/subscriptions","organizations_url":"https://api.github.com/users/martong/orgs","repos_url":"https://api.github.com/users/martong/repos","events_url":"https://api.github.com/users/martong/events{/privacy}","received_events_url":"https://api.github.com/users/martong/received_events","type":"User","site_admin":false},"created_at":"2018-05-11T13:11:14Z","updated_at":"2018-05-11T13:11:14Z","author_association":"NONE","body":"This is not a lookup error, the parser behaves differently than we assumed (but that is also a correct and logical behavior).\r\n\r\nA `DeclContext` contains one DenseMap (`LookupPtr`) which maps names to lists.\r\nThe list is a special list `StoredDeclsList` which is optimized to have one element.\r\nDuring building the initial AST, the parser first adds the definition to the `DeclContext`.\r\n```\r\n(gdb) p ND->dump()\r\nClassTemplateDecl 0xb5fb68 <output.cc:2:7, line:3:14> col:14 B\r\n|-TemplateTypeParmDecl 0xb5fa20 <line:2:17, col:26> col:26 typename depth 0 index 0 T\r\n`-CXXRecordDecl 0xb5fad0 <line:3:7, col:14> col:14 struct B\r\n$31 = void\r\n(gdb) bt 4\r\n#0  clang::StoredDeclsList::setOnlyValue (this=0xb64c98, ND=0xb5fb68) at ../../git/llvm/tools/clang/include/clang/AST/DeclContextInternals.h:99\r\n#1  0x00007ffff6a94331 in clang::DeclContext::makeDeclVisibleInContextImpl (this=0xb28108, D=0xb5fb68, Internal=false) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1802\r\n#2  0x00007ffff6a93b29 in clang::DeclContext::makeDeclVisibleInContextWithFlags (this=0xb28108, D=0xb5fb68, Internal=false, Recoverable=true) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1752\r\n#3  0x00007ffff6a9398c in clang::DeclContext::addDecl (this=0xb28108, D=0xb5fb68) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1435\r\n```\r\n\r\nThen during parsing the second declaration (the forward decl) the parser again calls `DeclContext::addDecl` but that will not add a new element to the `StoredDeclsList` rarther it simply overwrites the old element with the most recent one.\r\n```\r\n#0  clang::NamedDecl::declarationReplaces (this=0xb600a8, OldD=0xb5fb68, IsKnownNewer=true) at ../../git/llvm/tools/clang/lib/AST/Decl.cpp:1596\r\n#1  0x00007ffff6a9659b in clang::StoredDeclsList::HandleRedeclaration (this=0xb64c98, D=0xb600a8, IsKnownNewer=true) at ../../git/llvm/tools/clang/include/clang/AST/DeclContextInternals.h:169\r\n#2  0x00007ffff6a94350 in clang::DeclContext::makeDeclVisibleInContextImpl (this=0xb28108, D=0xb600a8, Internal=false) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1806\r\n#3  0x00007ffff6a93b29 in clang::DeclContext::makeDeclVisibleInContextWithFlags (this=0xb28108, D=0xb600a8, Internal=false, Recoverable=true) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1752\r\n#4  0x00007ffff6a9398c in clang::DeclContext::addDecl (this=0xb28108, D=0xb600a8) at ../../git/llvm/tools/clang/lib/AST/DeclBase.cpp:1435\r\n```\r\n\r\n`NamedDecl::declarationReplaces` decides whether we should overwrite the existing decl or extend the list. Generally, every `Decl` which is redeclarable will be overwritten.\r\nThus, I assume we will have the same errors with normal classes and class template specializations too.\r\nFunctions are not affected, because there we import the whole redecl chain."}}
{"actor":{"display_login":"martong"}}