r249342 - Revert r107690 (for PR7417) and add a testcase that it breaks. The approach of
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 5 13:05:21 PDT 2015
Author: rsmith
Date: Mon Oct 5 15:05:21 2015
New Revision: 249342
URL: http://llvm.org/viewvc/llvm-project?rev=249342&view=rev
Log:
Revert r107690 (for PR7417) and add a testcase that it breaks. The approach of
that change turns out to not be reasonable: mutating the AST of a parsed
template during instantiation is not a sound thing to do, does not work across
chained PCH / modules builds, and is in any case a special-case workaround to a
more general problem that should be solved centrally.
Added:
cfe/trunk/test/SemaTemplate/instantiate-expr-6.cpp
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=249342&r1=249341&r2=249342&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct 5 15:05:21 2015
@@ -6613,12 +6613,6 @@ public:
friend class ArgumentPackSubstitutionRAII;
- /// \brief The stack of calls expression undergoing template instantiation.
- ///
- /// The top of this stack is used by a fixit instantiating unresolved
- /// function calls to fix the AST to match the textual change it prints.
- SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
-
/// \brief For each declaration that involved template argument deduction, the
/// set of diagnostics that were suppressed during that template argument
/// deduction.
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=249342&r1=249341&r2=249342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 5 15:05:21 2015
@@ -1804,8 +1804,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXS
// unqualified lookup. This is useful when (for example) the
// original lookup would not have found something because it was a
// dependent name.
- DeclContext *DC = (SS.isEmpty() && !CallsUndergoingInstantiation.empty())
- ? CurContext : nullptr;
+ DeclContext *DC = SS.isEmpty() ? CurContext : nullptr;
while (DC) {
if (isa<CXXRecordDecl>(DC)) {
LookupQualifiedName(R, DC);
@@ -1833,47 +1832,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXS
if (isInstance) {
Diag(R.getNameLoc(), diagnostic) << Name
<< FixItHint::CreateInsertion(R.getNameLoc(), "this->");
- UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(
- CallsUndergoingInstantiation.back()->getCallee());
-
- CXXMethodDecl *DepMethod;
- if (CurMethod->isDependentContext()) {
- DepMethod = CurMethod;
- } else if (FunctionTemplateDecl *FTD =
- CurMethod->getPrimaryTemplate()) {
- // We have a member function template. It may be contained in a
- // class template. If so, get the original pattern for the member
- // function template. Otherwise, 'this' isn't dependent and we can
- // use CurMethod as is.
- if (FunctionTemplateDecl *MemberFTD =
- FTD->getInstantiatedFromMemberTemplate())
- DepMethod = cast<CXXMethodDecl>(MemberFTD->getTemplatedDecl());
- else
- DepMethod = CurMethod;
- } else {
- DepMethod = cast<CXXMethodDecl>(
- CurMethod->getInstantiatedFromMemberFunction());
- }
- assert(DepMethod && "No template pattern found");
-
- QualType DepThisType = DepMethod->getThisType(Context);
CheckCXXThisCapture(R.getNameLoc());
- CXXThisExpr *DepThis = new (Context) CXXThisExpr(
- R.getNameLoc(), DepThisType, false);
- TemplateArgumentListInfo TList;
- if (ULE->hasExplicitTemplateArgs())
- ULE->copyTemplateArgumentsInto(TList);
-
- CXXScopeSpec SS;
- SS.Adopt(ULE->getQualifierLoc());
- CXXDependentScopeMemberExpr *DepExpr =
- CXXDependentScopeMemberExpr::Create(
- Context, DepThis, DepThisType, true, SourceLocation(),
- SS.getWithLocInContext(Context),
- ULE->getTemplateKeywordLoc(), nullptr,
- R.getLookupNameInfo(),
- ULE->hasExplicitTemplateArgs() ? &TList : nullptr);
- CallsUndergoingInstantiation.back()->setCallee(DepExpr);
} else {
Diag(R.getNameLoc(), diagnostic) << Name;
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=249342&r1=249341&r2=249342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Oct 5 15:05:21 2015
@@ -817,14 +817,6 @@ namespace {
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
SubstTemplateTypeParmPackTypeLoc TL);
- ExprResult TransformCallExpr(CallExpr *CE) {
- getSema().CallsUndergoingInstantiation.push_back(CE);
- ExprResult Result =
- TreeTransform<TemplateInstantiator>::TransformCallExpr(CE);
- getSema().CallsUndergoingInstantiation.pop_back();
- return Result;
- }
-
ExprResult TransformLambdaExpr(LambdaExpr *E) {
LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E);
Added: cfe/trunk/test/SemaTemplate/instantiate-expr-6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-6.cpp?rev=249342&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-6.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-6.cpp Mon Oct 5 15:05:21 2015
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm-only %s
+
+struct X {
+ template<typename T> static typename T::type g(T t);
+ template<typename T> auto f(T t) -> decltype(g(t));
+ void f(...);
+};
+
+void test() {
+ X().f(0);
+ X().f(0);
+}
Modified: cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp?rev=249342&r1=249341&r2=249342&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp Mon Oct 5 15:05:21 2015
@@ -4,8 +4,8 @@
template <class T>
class A {
public:
- void f(T a) { }// expected-note {{must qualify identifier to find this declaration in dependent base class}}
- void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
+ void f(T a) { }// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
+ void g();// expected-note 2{{must qualify identifier to find this declaration in dependent base class}}
};
template <class T>
@@ -13,13 +13,13 @@ class B : public A<T> {
public:
void z(T a)
{
- f(a); // expected-warning {{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
- g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
+ f(a); // expected-warning 2{{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
+ g(); // expected-warning 2{{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
}
};
template class B<int>; // expected-note {{requested here}}
-template class B<char>;
+template class B<char>; // expected-note {{requested here}}
void test()
{
More information about the cfe-commits
mailing list