forked from OSchip/llvm-project
When a type's definition is instantiated, the definition becomes visible, even
if the type's declaration was previously instantiated in an unimported module. (For an imported type definition, this already worked, because the source location is set to the location of the definition, but for locally-instantiated type definitions, it did not.) llvm-svn: 203425
This commit is contained in:
parent
f703132b09
commit
a108760b33
|
@ -2018,7 +2018,7 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
|||
Spec->setTemplateSpecializationKind(TSK);
|
||||
Spec->setPointOfInstantiation(PointOfInstantiation);
|
||||
}
|
||||
|
||||
|
||||
InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
|
||||
if (Inst.isInvalid())
|
||||
return true;
|
||||
|
@ -2040,7 +2040,12 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
|||
|
||||
// Start the definition of this instantiation.
|
||||
Instantiation->startDefinition();
|
||||
|
||||
|
||||
// The instantiation is visible here, even if it was first declared in an
|
||||
// unimported module.
|
||||
Instantiation->setHidden(false);
|
||||
|
||||
// FIXME: This loses the as-written tag kind for an explicit instantiation.
|
||||
Instantiation->setTagKind(Pattern->getTagKind());
|
||||
|
||||
// Do substitution on the base class specifiers.
|
||||
|
@ -2167,6 +2172,8 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
|||
|
||||
ActOnFinishDelayedMemberInitializers(Instantiation);
|
||||
|
||||
// FIXME: We should do something similar for explicit instantiations so they
|
||||
// end up in the right module.
|
||||
if (TSK == TSK_ImplicitInstantiation) {
|
||||
Instantiation->setLocation(Pattern->getLocation());
|
||||
Instantiation->setLocStart(Pattern->getInnerLocStart());
|
||||
|
@ -2256,6 +2263,10 @@ bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation,
|
|||
if (Inst.isInvalid())
|
||||
return true;
|
||||
|
||||
// The instantiation is visible here, even if it was first declared in an
|
||||
// unimported module.
|
||||
Instantiation->setHidden(false);
|
||||
|
||||
// Enter the scope of this instantiation. We don't use
|
||||
// PushDeclContext because we don't have a scope.
|
||||
ContextRAII SavedContext(*this, Instantiation);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef A_H
|
||||
#define A_H
|
||||
template<typename T> struct S;
|
||||
template<typename U> struct T {
|
||||
struct S;
|
||||
enum E : int;
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef B_H
|
||||
#define B_H
|
||||
#include "a.h"
|
||||
S<int> *s1;
|
||||
T<int>::S *s2;
|
||||
T<int>::E e1;
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef C_H
|
||||
#define C_H
|
||||
template<typename T> struct S { int n; };
|
||||
template<typename U> struct T<U>::S { int n; };
|
||||
template<typename U> enum T<U>::E : int { e };
|
||||
#endif
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef D_H
|
||||
#define D_H
|
||||
template<typename> struct S;
|
||||
template<typename> struct T;
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef E_H
|
||||
#define E_H
|
||||
#include "c.h"
|
||||
template struct S<char>;
|
||||
template struct T<char>;
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
module tsv {
|
||||
module a { header "a.h" }
|
||||
module b { header "b.h" }
|
||||
module c { header "c.h" }
|
||||
module d { header "d.h" }
|
||||
module e { header "e.h" }
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// RUN: rm -rf %t
|
||||
// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 %s
|
||||
//
|
||||
// FIXME: We should accept the explicit instantiation cases below too.
|
||||
// Note, errors trigger implicit imports, so only enable one error at a time.
|
||||
// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR1 %s
|
||||
// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR2 %s
|
||||
// RUN: %clang_cc1 -fmodules -verify -fmodules-cache-path=%t -I %S/Inputs/template-specialization-visibility -std=c++11 -DERR3 %s
|
||||
|
||||
#include "c.h"
|
||||
|
||||
S<int> implicit_inst_class_template;
|
||||
int k1 = implicit_inst_class_template.n;
|
||||
|
||||
#ifdef ERR1
|
||||
S<char> explicit_inst_class_template; // expected-error {{must be imported from module 'tsv.e'}}
|
||||
// expected-note@e.h:4 {{previous}}
|
||||
int k2 = explicit_inst_class_template.n;
|
||||
#endif
|
||||
|
||||
#include "a.h"
|
||||
|
||||
T<int>::S implicit_inst_member_class_template;
|
||||
int k3 = implicit_inst_member_class_template.n;
|
||||
|
||||
#ifdef ERR2
|
||||
T<char>::S explicit_inst_member_class_template; // expected-error {{must be imported from module 'tsv.e'}}
|
||||
// expected-note@e.h:5 {{previous}}
|
||||
int k4 = explicit_inst_member_class_template.n;
|
||||
#endif
|
||||
|
||||
T<int>::E implicit_inst_member_enum_template;
|
||||
int k5 = decltype(implicit_inst_member_enum_template)::e;
|
||||
|
||||
#ifdef ERR3
|
||||
T<char>::E explicit_inst_member_enum_template; // expected-error {{must be imported from module 'tsv.e'}}
|
||||
// expected-note@e.h:5 {{previous}}
|
||||
int k6 = decltype(explicit_inst_member_enum_template)::e;
|
||||
#endif
|
||||
|
||||
#if ERR1 + ERR2 + ERR3 == 0
|
||||
// expected-no-diagnostics
|
||||
#endif
|
Loading…
Reference in New Issue