[PATCH] D29401: Fix MSVC Compatibility around dependent type with missing 'typename'

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 1 09:52:20 PST 2017


erichkeane created this revision.

As we know, MSVC is pretty relaxed when it comes to 'typename'.  Clang so far does a pretty darn good job of permitting the behavior, however there was 1 missed case that compiles in MSVC (as of 2015), but not in clang.  I've updated the test for similar ones that also/still pass, but were not tested.

  template<typename T>
  struct S { 
    typedef int TD;
  };
  template<class TMP>
  void foo() {
    S<TMP>::TD varname =0;
  }
  
  void foo2(){
    foo<int>();
  }

The above was previously an error in clang in -fms-compatibility mode.  This patch alters the parser in MSVC mode to correctly assume the 'typename' above where necessary.


https://reviews.llvm.org/D29401

Files:
  lib/Parse/ParseStmt.cpp
  test/SemaCXX/MicrosoftCompatibility.cpp


Index: lib/Parse/ParseStmt.cpp
===================================================================
--- lib/Parse/ParseStmt.cpp
+++ lib/Parse/ParseStmt.cpp
@@ -183,7 +183,8 @@
 
     // Look up the identifier, and typo-correct it to a keyword if it's not
     // found.
-    if (Next.isNot(tok::coloncolon)) {
+    if (Next.isNot(tok::coloncolon) && (!getLangOpts().MSVCCompat ||
+        Next.isNot(tok::less))) {
       // Try to limit which sets of keywords should be included in typo
       // correction based on what the next token is.
       if (TryAnnotateName(/*IsAddressOfOperand*/ false,
Index: test/SemaCXX/MicrosoftCompatibility.cpp
===================================================================
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -218,6 +218,9 @@
 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
 {
     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+    const A<T>::TYPE var2 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+    A<T>::TYPE var3 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+    MissingTypename::A<T>::TYPE var4 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
 }
 
 template void function_missing_typename<D>(const D::Type param);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29401.86659.patch
Type: text/x-patch
Size: 1436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170201/f1dddd21/attachment.bin>


More information about the cfe-commits mailing list