r212788 - [modules] Don't try to merge template specializations by performing name lookup
Richard Smith
richard-llvm at metafoo.co.uk
Thu Jul 10 17:20:07 PDT 2014
Author: rsmith
Date: Thu Jul 10 19:20:06 2014
New Revision: 212788
URL: http://llvm.org/viewvc/llvm-project?rev=212788&view=rev
Log:
[modules] Don't try to merge template specializations by performing name lookup
into their container; we won't find them there. These things are already being
merged when they're added to their primary template's folding set, so this
merging is redundant (and causes us to reject-valid because we think we've
found an odr violation).
Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
cfe/trunk/test/Modules/Inputs/cxx-templates-b.h
cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
cfe/trunk/test/Modules/cxx-templates.cpp
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=212788&r1=212787&r2=212788&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jul 10 19:20:06 2014
@@ -1017,7 +1017,8 @@ ASTDeclReader::RedeclarableResult ASTDec
switch ((VarKind)Record[Idx++]) {
case VarNotTemplate:
// Only true variables (not parameters or implicit parameters) can be merged
- if (VD->getKind() != Decl::ParmVar && VD->getKind() != Decl::ImplicitParam)
+ if (VD->getKind() != Decl::ParmVar && VD->getKind() != Decl::ImplicitParam &&
+ !isa<VarTemplateSpecializationDecl>(VD))
mergeRedeclarable(VD, Redecl);
break;
case VarTemplate:
@@ -1438,7 +1439,9 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CX
};
switch ((CXXRecKind)Record[Idx++]) {
case CXXRecNotTemplate:
- mergeRedeclarable(D, Redecl);
+ // Merged when we merge the folding set entry in the primary template.
+ if (!isa<ClassTemplateSpecializationDecl>(D))
+ mergeRedeclarable(D, Redecl);
break;
case CXXRecTemplate: {
// Merged when we merge the template.
Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-a.h?rev=212788&r1=212787&r2=212788&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-a.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-a.h Thu Jul 10 19:20:06 2014
@@ -63,3 +63,7 @@ template<> struct WithExplicitSpecializa
return n;
}
};
+
+template<typename T> template<typename U>
+constexpr int Outer<T>::Inner<U>::f() { return 1; }
+static_assert(Outer<int>::Inner<int>::f() == 1, "");
Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-b.h?rev=212788&r1=212787&r2=212788&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-b.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-b.h Thu Jul 10 19:20:06 2014
@@ -20,6 +20,10 @@ extern DefinedInCommon &defined_in_commo
template<int> struct MergeTemplates;
MergeTemplates<0> *merge_templates_b;
+template<typename T> template<typename U>
+constexpr int Outer<T>::Inner<U>::g() { return 2; }
+static_assert(Outer<int>::Inner<int>::g() == 2, "");
+
@import cxx_templates_b_impl;
template<typename T, typename> struct Identity { typedef T type; };
Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-common.h?rev=212788&r1=212787&r2=212788&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-common.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-common.h Thu Jul 10 19:20:06 2014
@@ -26,8 +26,8 @@ template<typename T> struct TemplateInst
template<typename T> struct Outer {
template<typename U> struct Inner {
- void f();
- void g();
+ static constexpr int f();
+ static constexpr int g();
};
};
Modified: cfe/trunk/test/Modules/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/cxx-templates.cpp?rev=212788&r1=212787&r2=212788&view=diff
==============================================================================
--- cfe/trunk/test/Modules/cxx-templates.cpp (original)
+++ cfe/trunk/test/Modules/cxx-templates.cpp Thu Jul 10 19:20:06 2014
@@ -107,6 +107,9 @@ void g() {
int &q = WithExplicitSpecializationUse().inner_template<int>();
}
+static_assert(Outer<int>::Inner<int>::f() == 1, "");
+static_assert(Outer<int>::Inner<int>::g() == 2, "");
+
RedeclaredAsFriend<int> raf1;
RedeclareTemplateAsFriend<double> rtaf;
RedeclaredAsFriend<double> raf2;
More information about the cfe-commits
mailing list