]> granicus.if.org Git - clang/commitdiff
In Microsoft mode, if we are inside a template class member function and we can't...
authorFrancois Pichet <pichet2000@gmail.com>
Wed, 7 Sep 2011 00:14:57 +0000 (00:14 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Wed, 7 Sep 2011 00:14:57 +0000 (00:14 +0000)
With this patch in, clang will generate only 37 errors (down from 212) when parsing a typical MFC source file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139210 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
lib/Sema/SemaOverload.cpp
test/SemaTemplate/ms-lookup-template-base-classes.cpp [new file with mode: 0644]

index 4143fef781d51d2afcb4f085fb38683285a3707a..e39a2c72f3882863e5fd385dab5f39ced1d6728e 100644 (file)
@@ -2392,6 +2392,9 @@ def err_unexpected_typedef : Error<
 def err_unexpected_namespace : Error<
   "unexpected namespace name %0: expected expression">;
 def err_undeclared_var_use : Error<"use of undeclared identifier %0">;
+def warn_found_via_dependent_bases_lookup : ExtWarn<"use of identifier %0 "
+   "found via unqualified lookup into dependent bases of class templates is a "
+   "Microsoft extension">, InGroup<Microsoft>;
 def note_dependent_var_use : Note<"must qualify identifier to find this "
     "declaration in dependent base class">;
 def err_not_found_by_two_phase_lookup : Error<"call to function %0 that is neither "
index 076602fa7b577f7b1684b18d6e132251c67dd97e..cbcbef91f72c2604382a93e510df68576e401046 100644 (file)
@@ -1456,6 +1456,8 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
           CXXMethodDecl *DepMethod = cast_or_null<CXXMethodDecl>(
               CurMethod->getInstantiatedFromMemberFunction());
           if (DepMethod) {
+            if (getLangOptions().Microsoft)
+              diagnostic = diag::warn_found_via_dependent_bases_lookup;
             Diag(R.getNameLoc(), diagnostic) << Name
               << FixItHint::CreateInsertion(R.getNameLoc(), "this->");
             QualType DepThisType = DepMethod->getThisType(Context);
index 6f3b1aa7bf598019d7a551a7bcb3390e74be7371..4f36189ce567ef7d630bdd7c219607b762456da4 100644 (file)
@@ -8289,9 +8289,22 @@ Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE,
   // If we found nothing, try to recover.
   // BuildRecoveryCallExpr diagnoses the error itself, so we just bail
   // out if it fails.
-  if (CandidateSet.empty())
+  if (CandidateSet.empty()) {
+    // In Microsoft mode, if we are inside a template class member function then\r
+    // create a type dependent CallExpr. The goal is to postpone name lookup\r
+    // to instantiation time to be able to search into type dependent base
+    // classes.\r
+    if (getLangOptions().Microsoft && CurContext->isDependentContext() && \r
+        isa<CXXMethodDecl>(CurContext)) {\r
+      CallExpr *CE = new (Context) CallExpr(Context, Fn, Args, NumArgs,\r
+                                          Context.DependentTy, VK_RValue,\r
+                                          RParenLoc);\r
+      CE->setTypeDependent(true);\r
+      return Owned(CE);\r
+    }\r
     return BuildRecoveryCallExpr(*this, S, Fn, ULE, LParenLoc, Args, NumArgs,
                                  RParenLoc, /*EmptyLookup=*/true);
+  }
 
   OverloadCandidateSet::iterator Best;
   switch (CandidateSet.BestViableFunction(*this, Fn->getLocStart(), Best)) {
diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp
new file mode 100644 (file)
index 0000000..910fa37
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
+
+
+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}}
+};
+
+
+template <class T>
+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}}
+    }
+};
+
+template class B<int>; // expected-note {{requested here}}
+template class B<char>;
+
+void test()
+{
+    B<int> b;
+    b.z(3);
+}
+
+