r203425 - When a type's definition is instantiated, the definition becomes visible, even

Richard Smith richard-llvm at metafoo.co.uk
Sun Mar 9 17:04:29 PDT 2014


Author: rsmith
Date: Sun Mar  9 19:04:29 2014
New Revision: 203425

URL: http://llvm.org/viewvc/llvm-project?rev=203425&view=rev
Log:
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.)

Added:
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/a.h
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/b.h
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/c.h
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/d.h
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/e.h
    cfe/trunk/test/Modules/Inputs/template-specialization-visibility/module.map
    cfe/trunk/test/Modules/template-specialization-visibility.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=203425&r1=203424&r2=203425&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sun Mar  9 19:04:29 2014
@@ -2018,7 +2018,7 @@ Sema::InstantiateClass(SourceLocation Po
     Spec->setTemplateSpecializationKind(TSK);
     Spec->setPointOfInstantiation(PointOfInstantiation);
   }
-  
+
   InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
   if (Inst.isInvalid())
     return true;
@@ -2040,7 +2040,12 @@ Sema::InstantiateClass(SourceLocation Po
 
   // 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 Po
 
   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(SourceLocatio
   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);

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/a.h?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/a.h Sun Mar  9 19:04:29 2014
@@ -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

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/b.h?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/b.h Sun Mar  9 19:04:29 2014
@@ -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

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/c.h?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/c.h (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/c.h Sun Mar  9 19:04:29 2014
@@ -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

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/d.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/d.h?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/d.h (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/d.h Sun Mar  9 19:04:29 2014
@@ -0,0 +1,5 @@
+#ifndef D_H
+#define D_H
+template<typename> struct S;
+template<typename> struct T;
+#endif

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/e.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/e.h?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/e.h (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/e.h Sun Mar  9 19:04:29 2014
@@ -0,0 +1,6 @@
+#ifndef E_H
+#define E_H
+#include "c.h"
+template struct S<char>;
+template struct T<char>;
+#endif

Added: cfe/trunk/test/Modules/Inputs/template-specialization-visibility/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/template-specialization-visibility/module.map?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/template-specialization-visibility/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/template-specialization-visibility/module.map Sun Mar  9 19:04:29 2014
@@ -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" }
+}

Added: cfe/trunk/test/Modules/template-specialization-visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/template-specialization-visibility.cpp?rev=203425&view=auto
==============================================================================
--- cfe/trunk/test/Modules/template-specialization-visibility.cpp (added)
+++ cfe/trunk/test/Modules/template-specialization-visibility.cpp Sun Mar  9 19:04:29 2014
@@ -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 at 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 at 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 at e.h:5 {{previous}}
+int k6 = decltype(explicit_inst_member_enum_template)::e;
+#endif
+
+#if ERR1 + ERR2 + ERR3 == 0
+// expected-no-diagnostics
+#endif





More information about the cfe-commits mailing list