]> granicus.if.org Git - clang/commitdiff
Allow the parser to recover gracefully if a typename is used to introduce a decltype...
authorFrancois Pichet <pichet2000@gmail.com>
Sun, 22 Jul 2012 15:10:57 +0000 (15:10 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Sun, 22 Jul 2012 15:10:57 +0000 (15:10 +0000)
In Microsoft mode, we emit a warning instead of an error.

This fixes a couple of errors when parsing the MSVC 11 RC headers with clang.

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

lib/Parse/Parser.cpp
test/SemaCXX/MicrosoftCompatibility.cpp

index e95af05411185f59781eb2fa54feb3f5a135c41f..760c7bf717a2dc937cc8fa61c08664db8d40d4fa 100644 (file)
@@ -1334,10 +1334,12 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) {
                                        0, /*IsTypename*/true))
       return true;
     if (!SS.isSet()) {
-      if (Tok.is(tok::identifier) || Tok.is(tok::annot_template_id)) {
+      if (Tok.is(tok::identifier) || Tok.is(tok::annot_template_id) ||
+          Tok.is(tok::annot_decltype)) {
         // Attempt to recover by skipping the invalid 'typename'
-        if (!TryAnnotateTypeOrScopeToken(EnteringContext, NeedType) &&
-            Tok.isAnnotation()) {
+        if (Tok.is(tok::annot_decltype) ||
+            (!TryAnnotateTypeOrScopeToken(EnteringContext, NeedType) &&
+            Tok.isAnnotation())) {
           unsigned DiagID = diag::err_expected_qualified_after_typename;
           // MS compatibility: MSVC permits using known types with typename.
           // e.g. "typedef typename T* pointer_type"
index 74d54ef99417cdec25e8016e4d121e4e44085185..6a48f36801bdfe887b86f26002a30010e04bef4d 100644 (file)
@@ -4,6 +4,8 @@
 typedef unsigned short char16_t;
 typedef unsigned int char32_t;
 
+typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
+
 namespace ms_conversion_rules {
 
 void f(float a);