[PATCH] D53441: [ms] Prevent explicit constructor name lookup if scope is missing

2018-10-19 Thread Will Wilson via Phabricator via cfe-commits
lantictac created this revision.
lantictac added a reviewer: rsmith.
lantictac added a project: clang.

MicrosoftExt allows explicit constructor calls. Prevent lookup of constructor 
name unless the name has explicit scope.
This avoids a compile-time crash due to confusing a member access for a 
constructor name.

Test case included. All tests pass.


Repository:
  rC Clang

https://reviews.llvm.org/D53441

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


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -302,3 +302,23 @@
   void *a2 = &function_prototype; // expected-warning {{implicit conversion 
between pointer-to-function and pointer-to-object is a Microsoft extension}}
   void *a3 = function_ptr;// expected-warning {{implicit conversion 
between pointer-to-function and pointer-to-object is a Microsoft extension}}
 }
+
+namespace member_lookup {
+
+template
+struct ConfuseLookup {
+  T* m_val;
+  struct m_val {
+static size_t ms_test;
+  };
+};
+
+// Microsoft mode allows explicit constructor calls
+// This could confuse name lookup in cases such as this
+template
+size_t ConfuseLookup::m_val::ms_test
+  = size_t(&(char&)(reinterpret_cast*>(0)->m_val));
+
+void instantiate() { ConfuseLookup::m_val::ms_test = 1; }
+}
+
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1809,7 +1809,8 @@
 /*EnteringContext=*/false,
 /*AllowDestructorName=*/true,
 /*AllowConstructorName=*/
-  getLangOpts().MicrosoftExt,
+getLangOpts().MicrosoftExt &&
+SS.isNotEmpty(),
 /*AllowDeductionGuide=*/false,
 ObjectType, &TemplateKWLoc, Name)) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -302,3 +302,23 @@
   void *a2 = &function_prototype; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
   void *a3 = function_ptr;// expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
 }
+
+namespace member_lookup {
+
+template
+struct ConfuseLookup {
+  T* m_val;
+  struct m_val {
+static size_t ms_test;
+  };
+};
+
+// Microsoft mode allows explicit constructor calls
+// This could confuse name lookup in cases such as this
+template
+size_t ConfuseLookup::m_val::ms_test
+  = size_t(&(char&)(reinterpret_cast*>(0)->m_val));
+
+void instantiate() { ConfuseLookup::m_val::ms_test = 1; }
+}
+
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1809,7 +1809,8 @@
 /*EnteringContext=*/false,
 /*AllowDestructorName=*/true,
 /*AllowConstructorName=*/
-  getLangOpts().MicrosoftExt,
+getLangOpts().MicrosoftExt &&
+SS.isNotEmpty(),
 /*AllowDeductionGuide=*/false,
 ObjectType, &TemplateKWLoc, Name)) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53441: [ms] Prevent explicit constructor name lookup if scope is missing

2018-10-25 Thread Will Wilson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC345258: [ms] Prevent explicit constructor name lookup if 
scope is missing (authored by lantictac, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D53441

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


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -302,3 +302,23 @@
   void *a2 = &function_prototype; // expected-warning {{implicit conversion 
between pointer-to-function and pointer-to-object is a Microsoft extension}}
   void *a3 = function_ptr;// expected-warning {{implicit conversion 
between pointer-to-function and pointer-to-object is a Microsoft extension}}
 }
+
+namespace member_lookup {
+
+template
+struct ConfuseLookup {
+  T* m_val;
+  struct m_val {
+static size_t ms_test;
+  };
+};
+
+// Microsoft mode allows explicit constructor calls
+// This could confuse name lookup in cases such as this
+template
+size_t ConfuseLookup::m_val::ms_test
+  = size_t(&(char&)(reinterpret_cast*>(0)->m_val));
+
+void instantiate() { ConfuseLookup::m_val::ms_test = 1; }
+}
+
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1809,7 +1809,8 @@
 /*EnteringContext=*/false,
 /*AllowDestructorName=*/true,
 /*AllowConstructorName=*/
-  getLangOpts().MicrosoftExt,
+getLangOpts().MicrosoftExt &&
+SS.isNotEmpty(),
 /*AllowDeductionGuide=*/false,
 ObjectType, &TemplateKWLoc, Name)) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -302,3 +302,23 @@
   void *a2 = &function_prototype; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
   void *a3 = function_ptr;// expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
 }
+
+namespace member_lookup {
+
+template
+struct ConfuseLookup {
+  T* m_val;
+  struct m_val {
+static size_t ms_test;
+  };
+};
+
+// Microsoft mode allows explicit constructor calls
+// This could confuse name lookup in cases such as this
+template
+size_t ConfuseLookup::m_val::ms_test
+  = size_t(&(char&)(reinterpret_cast*>(0)->m_val));
+
+void instantiate() { ConfuseLookup::m_val::ms_test = 1; }
+}
+
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1809,7 +1809,8 @@
 /*EnteringContext=*/false,
 /*AllowDestructorName=*/true,
 /*AllowConstructorName=*/
-  getLangOpts().MicrosoftExt,
+getLangOpts().MicrosoftExt &&
+SS.isNotEmpty(),
 /*AllowDeductionGuide=*/false,
 ObjectType, &TemplateKWLoc, Name)) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits