[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.
llvm-svn: 140452
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 31eb19e..c06f5a7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1690,6 +1690,16 @@
// 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<CXXMethodDecl>(CurContext))
+ return ActOnDependentIdExpression(SS, NameInfo, IsAddressOfOperand,
+ TemplateArgs);
+
if (DiagnoseEmptyLookup(S, SS, R, CTC_Unknown))
return ExprError();
diff --git a/clang/test/SemaCXX/MicrosoftCompatibility.cpp b/clang/test/SemaCXX/MicrosoftCompatibility.cpp
index 788fcfb..1370b7d 100644
--- a/clang/test/SemaCXX/MicrosoftCompatibility.cpp
+++ b/clang/test/SemaCXX/MicrosoftCompatibility.cpp
@@ -134,3 +134,25 @@
template void function_missing_typename<D>();
}
+
+
+
+namespace lookup_dependent_bases_id_expr {
+
+template<class T> class A {
+public:
+ int var;
+};
+
+
+template<class T>
+class B : public A<T> {
+public:
+ void f() {
+ var = 3;
+ }
+};
+
+template class B<int>;
+
+}
\ No newline at end of file