From caa02f879f569de2c0d912e670f0edbb647ed3a4 Mon Sep 17 00:00:00 2001 From: Will Wilson Date: Thu, 25 Oct 2018 11:45:32 +0000 Subject: [PATCH] [ms] Prevent explicit constructor name lookup if scope is missing 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. Differential Revision: https://reviews.llvm.org/D53441 llvm-svn: 345258 --- clang/lib/Parse/ParseExpr.cpp | 3 ++- clang/test/SemaCXX/MicrosoftCompatibility.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index b9028bf..54733d8 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1809,7 +1809,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { /*EnteringContext=*/false, /*AllowDestructorName=*/true, /*AllowConstructorName=*/ - getLangOpts().MicrosoftExt, + getLangOpts().MicrosoftExt && + SS.isNotEmpty(), /*AllowDeductionGuide=*/false, ObjectType, &TemplateKWLoc, Name)) { (void)Actions.CorrectDelayedTyposInExpr(LHS); diff --git a/clang/test/SemaCXX/MicrosoftCompatibility.cpp b/clang/test/SemaCXX/MicrosoftCompatibility.cpp index 203a810..727e675 100644 --- a/clang/test/SemaCXX/MicrosoftCompatibility.cpp +++ b/clang/test/SemaCXX/MicrosoftCompatibility.cpp @@ -302,3 +302,23 @@ void function_to_voidptr_conv() { 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; } +} + -- 2.7.4