]> granicus.if.org Git - clang/commit
When we perform dependent name lookup during template instantiation, it's not
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Jul 2013 23:08:39 +0000 (23:08 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 25 Jul 2013 23:08:39 +0000 (23:08 +0000)
commitb775100fea6d8955149897dae1adca50ca471d17
tree46dd2d5370387f61ac7835d9be42365fea0dd213
parentd78aef1f8339fbe6784bf1628dcec19ca1af2b6c
When we perform dependent name lookup during template instantiation, it's not
sufficient to only consider names visible at the point of instantiation,
because that may not include names that were visible when the template was
defined. More generally, if the instantiation backtrace goes through a module
M, then every declaration visible within M should be available to the
instantiation. Any of those declarations might be part of the interface that M
intended to export to a template that it instantiates.

The fix here has two parts:

1) If we find a non-visible declaration during name lookup during template
instantiation, check whether the declaration was visible from the defining
module of all entities on the active template instantiation stack. The defining
module is not the owning module in all cases: we look at the module in which a
template was defined, not the module in which it was first instantiated.

2) Perform pending instantiations at the end of a module, not at the end of the
translation unit. This is general goodness, since it significantly cuts down
the amount of redundant work that is performed in every TU importing a module,
and also implicitly adds the module containing the point of instantiation to
the set of modules checked for declarations in a lookup within a template
instantiation.

There's a known issue here with template instantiations performed while
building a module, if additional imports are added later on. I'll fix that
in a subsequent commit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187167 91177308-0d34-0410-b5e6-96231b3b80d8
15 files changed:
include/clang/AST/DeclBase.h
include/clang/Basic/Module.h
include/clang/Sema/Lookup.h
include/clang/Sema/Sema.h
lib/Basic/Module.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaLookup.cpp
lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaType.cpp
test/Modules/Inputs/cxx-templates-a.h
test/Modules/Inputs/cxx-templates-b-impl.h [new file with mode: 0644]
test/Modules/Inputs/cxx-templates-b.h
test/Modules/Inputs/cxx-templates-common.h
test/Modules/Inputs/module.map
test/Modules/cxx-templates.cpp