From fce1a3ab56879a7eb92c7e0b465c1f2c07e0c512 Mon Sep 17 00:00:00 2001 From: Francois Pichet Date: Sat, 24 Sep 2011 10:38:05 +0000 Subject: [PATCH] [microsoft] In Microsoft mode, if we are inside a template class member function and we can't resolve an identifier then assume the identifier is type dependent. The goal is to postpone name lookup to instantiation time to be able to search into type dependent base classes. This fixes a few errors when parsing MFC code with clang. BTW clang trunk is now about 5 patches away to be able the parse the default wizard-generated MFC project. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140452 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 10 ++++++++++ test/SemaCXX/MicrosoftCompatibility.cpp | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 31eb19e174..c06f5a7b83 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1690,6 +1690,16 @@ ExprResult Sema::ActOnIdExpression(Scope *S, // If this name wasn't predeclared and if this is not a function // call, diagnose the problem. if (R.empty()) { + + // In Microsoft mode, if we are inside a template class member function + // and we can't resolve an identifier then assume the identifier is type + // dependent. The goal is to postpone name lookup to instantiation time + // to be able to search into type dependent base classes. + if (getLangOptions().MicrosoftMode && CurContext->isDependentContext() && + isa(CurContext)) + return ActOnDependentIdExpression(SS, NameInfo, IsAddressOfOperand, + TemplateArgs); + if (DiagnoseEmptyLookup(S, SS, R, CTC_Unknown)) return ExprError(); diff --git a/test/SemaCXX/MicrosoftCompatibility.cpp b/test/SemaCXX/MicrosoftCompatibility.cpp index 788fcfbff0..1370b7dbf4 100644 --- a/test/SemaCXX/MicrosoftCompatibility.cpp +++ b/test/SemaCXX/MicrosoftCompatibility.cpp @@ -134,3 +134,25 @@ void function_missing_typename() template void function_missing_typename(); } + + + +namespace lookup_dependent_bases_id_expr { + +template class A { +public: + int var; +}; + + +template +class B : public A { +public: + void f() { + var = 3; + } +}; + +template class B; + +} \ No newline at end of file -- 2.40.0