r233430 - [modules] Allow a function template definition if we have a pre-existing but not visible definition of the same template.
Richard Smith
richard-llvm at metafoo.co.uk
Fri Mar 27 14:57:42 PDT 2015
Author: rsmith
Date: Fri Mar 27 16:57:41 2015
New Revision: 233430
URL: http://llvm.org/viewvc/llvm-project?rev=233430&view=rev
Log:
[modules] Allow a function template definition if we have a pre-existing but not visible definition of the same template.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
cfe/trunk/test/Modules/submodules-merge-defs.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=233430&r1=233429&r2=233430&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 27 16:57:41 2015
@@ -10282,13 +10282,16 @@ Sema::CheckForFunctionRedefinition(Funct
if (canRedefineFunction(Definition, getLangOpts()))
return;
- // If we don't have a visible definition of the function, and it's inline,
- // it's OK to form another definition of it.
+ // If we don't have a visible definition of the function, and it's inline or
+ // a template, it's OK to form another definition of it.
//
// FIXME: Should we skip the body of the function and use the old definition
// in this case? That may be necessary for functions that return local types
// through a deduced return type, or instantiate templates with local types.
- if (!hasVisibleDefinition(Definition) && Definition->isInlineSpecified())
+ if (!hasVisibleDefinition(Definition) &&
+ (Definition->isInlineSpecified() ||
+ Definition->getDescribedFunctionTemplate() ||
+ Definition->getNumTemplateParameterLists()))
return;
if (getLangOpts().GNUMode && Definition->isInlineSpecified() &&
Modified: cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h?rev=233430&r1=233429&r2=233430&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h (original)
+++ cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h Fri Mar 27 16:57:41 2015
@@ -5,9 +5,11 @@ class B {
struct Inner1 {};
public:
struct Inner2;
+ template<typename T> void f();
};
// Check that lookup and access checks are performed in the right context.
struct B::Inner2 : Inner1 {};
+template<typename T> void B::f() {}
// Check that base-specifiers are correctly disambiguated.
template<int N> struct C_Base { struct D { constexpr operator int() const { return 0; } }; };
@@ -18,3 +20,12 @@ struct C2 : C_Base<C_Const<0>::D{} exter
typedef struct { int a; void f(); struct X; } D;
struct D::X { int dx; } extern dx;
inline int use_dx(D::X dx) { return dx.dx; }
+
+template<typename T> int E(T t) { return t; }
+
+template<typename T> struct F {
+ int f();
+ template<typename U> int g();
+};
+template<typename T> int F<T>::f() { return 0; }
+template<typename T> template<typename U> int F<T>::g() { return 0; }
Modified: cfe/trunk/test/Modules/submodules-merge-defs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-merge-defs.cpp?rev=233430&r1=233429&r2=233430&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules-merge-defs.cpp (original)
+++ cfe/trunk/test/Modules/submodules-merge-defs.cpp Fri Mar 27 16:57:41 2015
@@ -12,21 +12,28 @@ int pre_use_a = use_a(pre_a); // expecte
B::Inner2 pre_bi; // expected-error +{{must be imported}}
// expected-note at defs.h:4 +{{here}}
-// expected-note at defs.h:10 +{{here}}
+// expected-note at defs.h:11 +{{here}}
C_Base<1> pre_cb1; // expected-error +{{must be imported}}
-// expected-note at defs.h:13 +{{here}}
-C1 pre_c1; // expected-error +{{must be imported}} expected-error {{must use 'struct'}}
// expected-note at defs.h:15 +{{here}}
+C1 pre_c1; // expected-error +{{must be imported}} expected-error {{must use 'struct'}}
+// expected-note at defs.h:17 +{{here}}
C2 pre_c2; // expected-error +{{must be imported}} expected-error {{must use 'struct'}}
-// expected-note at defs.h:16 +{{here}}
+// expected-note at defs.h:18 +{{here}}
D::X pre_dx; // expected-error +{{must be imported}}
-// expected-note at defs.h:18 +{{here}}
-// expected-note at defs.h:19 +{{here}}
+// expected-note at defs.h:20 +{{here}}
+// expected-note at defs.h:21 +{{here}}
// FIXME: We should warn that use_dx is being used without being imported.
int pre_use_dx = use_dx(pre_dx);
+int pre_e = E(0); // expected-error {{must be imported}}
+// expected-note at defs.h:24 +{{here}}
+
+int pre_ff = F<int>().f(); // expected-error +{{must be imported}}
+int pre_fg = F<int>().g<int>(); // expected-error +{{must be imported}}
+// expected-note at defs.h:26 +{{here}}
+
// Make definitions from second module visible.
#ifdef TEXTUAL
#include "import-and-redefine.h"
@@ -42,3 +49,6 @@ C1 c1;
C2 c2;
D::X post_dx;
int post_use_dx = use_dx(post_dx);
+int post_e = E(0);
+int post_ff = F<char>().f();
+int post_fg = F<char>().g<int>();
More information about the cfe-commits
mailing list