]> granicus.if.org Git - clang/commitdiff
Do a second lookup for type_info in the global namespace in microsoft mode. PR13153.
authorNico Weber <nicolasweber@gmx.de>
Tue, 19 Jun 2012 23:58:27 +0000 (23:58 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 19 Jun 2012 23:58:27 +0000 (23:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158768 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp [new file with mode: 0644]

index 95dcbe9ad8d3426a1b3f11cb2d426764c86fb379..a053c2aed60c0e96e54862d43b6497a53300f096 100644 (file)
@@ -374,6 +374,12 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
     LookupResult R(*this, TypeInfoII, SourceLocation(), LookupTagName);
     LookupQualifiedName(R, getStdNamespace());
     CXXTypeInfoDecl = R.getAsSingle<RecordDecl>();
+    // Microsoft's typeinfo doesn't have type_info in std but in the global
+    // namespace if _HAS_EXCEPTIONS is defined to 0. See PR13153.
+    if (!CXXTypeInfoDecl && LangOpts.MicrosoftMode) {
+      LookupQualifiedName(R, Context.getTranslationUnitDecl());
+      CXXTypeInfoDecl = R.getAsSingle<RecordDecl>();
+    }
     if (!CXXTypeInfoDecl)
       return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
   }
diff --git a/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp b/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp
new file mode 100644 (file)
index 0000000..d932b5d
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility
+
+// PR13153
+namespace std {}
+class type_info {};
+void f() {
+  (void)typeid(int);
+}