From 16251bd5aff05d7a08009232b361b49556926708 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 8 Jul 2014 21:35:03 +0000 Subject: MS compat: Allow lookup of types from dependent bases in functions If we want to resolve the remaining FIXMEs here, we probably want to extend the main lookup mechanism to perform lookup into dependent bases, but we would have to tread lightly. Adding more name lookup has major impact on compile time. If we did extend the main mechanism, we would add a flag to LookupResult that allows us to find names from dependent base classes where the base is a specialization of a known template. The final LookupResult would still return LookupResult::NotFoundInCurrentInstantiation, but it would have a collection of Decls. If we find a real lookup result, we would clear the flag and the existing lookup results and begin accumulating only real lookup results. We would structure the lookup as a secondary lookup between normal lookup and typo correction for normal compilation, but for MSVC compatibility mode, we would always enable this extra lookup into dependent bases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212566 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../ms-lookup-template-base-classes.cpp | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'test/SemaTemplate/ms-lookup-template-base-classes.cpp') diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 635f0b0cd0..40f73c0d9e 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++1y -fms-compatibility -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++1y -fms-compatibility -fno-spell-checking -fsyntax-only -verify %s template @@ -380,6 +380,15 @@ struct B : A { NameFromBase m; }; // expected-error {{unknown type name 'Name struct C : A { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} } +namespace type_in_base_of_dependent_base { +struct A { typedef int NameFromBase; }; +template +struct B : A {}; +// FIXME: MSVC accepts this. +template +struct C : B { NameFromBase m; }; // expected-error {{unknown type name 'NameFromBase'}} +} + namespace lookup_in_function_contexts { template struct A { typedef T NameFromBase; }; template @@ -389,23 +398,20 @@ struct B : A { return {}; } - // FIXME: MSVC accepts all of the code below that isn't C++14 only. Downgrade - // these errors to warnings. - static void memberFunc() { - NameFromBase x; // expected-error {{unknown type name 'NameFromBase'}} + NameFromBase x; // expected-warning {{lookup into dependent bases}} } static void funcLocalClass() { struct X { - NameFromBase x; // expected-error {{unknown type name 'NameFromBase'}} + NameFromBase x; // expected-warning {{lookup into dependent bases}} } y; } void localClassMethod() { struct X { void bar() { - NameFromBase m; // expected-error {{unknown type name 'NameFromBase'}} + NameFromBase m; // expected-warning {{lookup into dependent bases}} } } x; x.bar(); @@ -413,20 +419,18 @@ struct B : A { static void funcLambda() { auto l = []() { - NameFromBase x; // expected-error {{unknown type name 'NameFromBase'}} + NameFromBase x; // expected-warning {{lookup into dependent bases}} }; l(); } static constexpr int constexprFunc() { - NameFromBase x = {}; // expected-error {{unknown type name 'NameFromBase'}} - // FIXME: Suppress this diagnostic, we have an initializer. - // expected-error@-2 {{variables defined in a constexpr function must be initialized}} + NameFromBase x = {}; // expected-warning {{lookup into dependent bases}} return sizeof(x); } static auto autoFunc() { - NameFromBase x; // expected-error {{unknown type name 'NameFromBase'}} + NameFromBase x; // expected-warning {{lookup into dependent bases}} return x; } }; -- cgit v1.2.1